void sub_write(char *arg, char_data *ch, byte find_invis, int targets) { char str[MAX_INPUT_LENGTH * 2]; char type[MAX_INPUT_LENGTH], name[MAX_INPUT_LENGTH]; char *tokens[MAX_INPUT_LENGTH], *s, *p; void *otokens[MAX_INPUT_LENGTH]; char_data *to; obj_data *obj; int i, tmp; int sleep = 1, deaf = 0; if (!arg) return; tokens[0] = str; for (i = 0, p = arg, s = str; *p;) { switch (*p) { case '~': case '@': case '^': case '&': case '*': /* get char_data, move to next token */ type[i] = *p; *s = '\0'; p = any_one_name(++p, name); // See comment below. //(char_data *)otokens[i] = find_invis ? get_char(name) : get_char_vis(ch, name, FIND_CHAR_ROOM); // I'm not sure why "otokens[i]" was cast to a char_data type. // Doing so caused GCC to complain, so I removed it. // Bran - '11 otokens[i] = find_invis ? get_char(name) : get_char_vis(ch, name, FIND_CHAR_ROOM); tokens[++i] = ++s; break; case '`': /* get obj_data, move to next token */ type[i] = *p; *s = '\0'; p = any_one_name(++p, name); //(obj_data *)otokens[i] = find_invis ? (obj = get_obj(name)) : otokens[i] = find_invis ? (obj = get_obj(name)) : ((obj = get_obj_in_list_vis(ch, name, world[IN_ROOM(ch)].contents)) ? obj : (obj = get_object_in_equip_vis(ch, name, ch->equipment, &tmp)) ? obj : (obj = get_obj_in_list_vis(ch, name, ch->carrying))); //if (find_invis) obj = get_obj_in_room(&world[IN_ROOM(ch)], name); //else if (!(obj = get_obj_in_list_vis(ch, name, world[IN_ROOM(ch)].contents))) ; //else if (!(obj = get_object_in_equip_vis(ch, name, &tmp, ch->equipment))); //else obj = get_obj_in_list_vis(ch, name, ch->carrying); //(obj_data *)otokens[i] = obj; // Once again I'm not sure why this was cast. // See comment above. otokens[i] = obj; tokens[++i] = ++s; break; case '\\': p++; *s++ = *p++; break; default: *s++ = *p++; } } *s = '\0'; tokens[++i] = NULL; if (IS_SET(targets, TO_CHAR) && SENDOK(ch)) sub_write_to_char(ch, tokens, otokens, type); if (IS_SET(targets, TO_ROOM)) for (to = world[ch->in_room].people; to; to = to->next_in_room) if (to != ch && SENDOK(to)) sub_write_to_char(to, tokens, otokens, type); }
void sub_write(char *arg, char_data *ch, byte find_invis, int targets) { char str[MAX_INPUT_LENGTH * 2]; char type[MAX_INPUT_LENGTH], name[MAX_INPUT_LENGTH]; char *tokens[MAX_INPUT_LENGTH], *s, *p; void *otokens[MAX_INPUT_LENGTH]; char_data *to; obj_data *obj; int i; int to_sleeping = 1, is_spammy = 0; /* mainly for windows compiles */ if (!arg) return; tokens[0] = str; for (i = 0, p = arg, s = str; *p;) { switch (*p) { case '~': case '|': case '^': // case '&': // removed this because it conflicts with color codes case '*': { /* get char_data, move to next token */ type[i] = *p; *s = '\0'; p = any_one_name(++p, name); otokens[i] = find_invis ? get_char_in_room(IN_ROOM(ch), name) : get_char_room_vis(ch, name); tokens[++i] = ++s; break; } case '@': { /* get obj_data, move to next token */ type[i] = *p; *s = '\0'; p = any_one_name(++p, name); if (find_invis) obj = get_obj_in_room(IN_ROOM(ch), name); else if (!(obj = get_obj_in_list_vis(ch, name, ROOM_CONTENTS(IN_ROOM(ch))))) { // nothing } else if (!(obj = get_obj_in_equip_vis(ch, name, ch->equipment))) { // nothing } else { obj = get_obj_in_list_vis(ch, name, ch->carrying); } otokens[i] = obj; tokens[++i] = ++s; break; } case '\\': { p++; *s++ = *p++; break; } default: { *s++ = *p++; } } } *s = '\0'; tokens[++i] = NULL; if (IS_SET(targets, TO_CHAR) && SENDOK(ch) && (AWAKE(ch) || IS_SET(targets, TO_SLEEP))) sub_write_to_char(ch, tokens, otokens, type); if (IS_SET(targets, TO_ROOM)) { for (to = ROOM_PEOPLE(IN_ROOM(ch)); to; to = to->next_in_room) { if (to != ch && SENDOK(to) && (AWAKE(to) || IS_SET(targets, TO_SLEEP))) { sub_write_to_char(to, tokens, otokens, type); } } } }
void sub_write(char *arg, char_data *ch, byte find_invis, int targets) { //char str[MAX_INPUT_LENGTH * 2]; // char type[MAX_INPUT_LENGTH], name[MAX_INPUT_LENGTH]; // char *tokens[MAX_INPUT_LENGTH], *s, *p; // void *otokens[MAX_INPUT_LENGTH]; char_data *to; // obj_data *obj; // int i, tmp; if (!arg) return; //tokens[0] = str; /* for (i = 0, p = arg, s = str; *p;) { switch (*p) { case '~': case '@': case '^': case '&': case '*': //get char_data, move to next token type[i] = *p; *s = '\0'; p = any_one_name(++p, name); (char_data *)otokens[i] = find_invis ? get_char(name) : get_char_room_vis(ch, name); tokens[++i] = ++s; break; case '`': // get obj_data, move to next token type[i] = *p; *s = '\0'; p = any_one_name(++p, name); (char_data *)otokens[i] = find_invis ? (obj = get_obj(name)) : ((obj = get_obj_in_list_vis(ch, name, world[IN_ROOM(ch)].contents)) ? obj : (obj = get_object_in_equip_vis(ch, name, ch->equipment, &tmp)) ? obj : (obj = get_obj_in_list_vis(ch, name, ch->carrying))); (obj_data *)otokens[i] = obj; tokens[++i] = ++s; break; case '\\': p++; *s++ = *p++; break; default: *s++ = *p++; } }*/ //*s = '\0'; //tokens[++i] = NULL; strcat(arg,"\n\r"); if (IS_SET(targets, TO_CHAR) && SENDOK(ch)) //sub_write_to_char(ch, tokens, otokens, type); send_to_char(arg, ch); if (IS_SET(targets, TO_ROOM)) for (to = world[ch->in_room].people; to; to = to->next_in_room) if (to != ch && SENDOK(to)) //sub_write_to_char(to, tokens, otokens, type); send_to_char(arg, to); }
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { HANDLE cld_r, cld_w2, cld_w; STARTUPINFO sinfo; enum fresh_states fstate = FRESH_PRE; AV_UPD_STATUS st = {UPD_CHECK, 0, 0, 0, L"", 0}; DWORD dw; struct my_f spam; char command[8192], *ptr; int updated_files = 0, customok = 0, mindefs = 0, customonly = 0; char *cmdl = GetCommandLineA(); //DebugBreak(); mindefs = (cmdl && strstr(cmdl, " --mindefs=1")); customonly = (cmdl && strstr(cmdl, " --customsigonly")); /* Locate myself */ dw = GetModuleFileName(NULL, datadir, sizeof(datadir)); if(!dw || dw >= sizeof(datadir)-2) return 10; ptr = strrchr(datadir, '\\'); if(!ptr) return 10; *ptr = '\0'; /* Log file */ flog_open(datadir); /* Connect to master */ updpipe = CreateFile("\\\\.\\pipe\\IMMUNET_AVUPDATE", GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_FLAG_OVERLAPPED, NULL); if(updpipe == INVALID_HANDLE_VALUE) { flog("ERROR: failed to connect pipe"); flog_close(); return 10; } dw = PIPE_READMODE_MESSAGE; if(!SetNamedPipeHandleState(updpipe, &dw, NULL, NULL)) { CloseHandle(updpipe); flog("ERROR: failed to set pipe to message mode"); flog_close(); return 10; } if(!(write_event = CreateEvent(NULL, TRUE, FALSE, NULL))) { CloseHandle(updpipe); flog("ERROR: failed to create write event"); flog_close(); return 10; } /* Run local-only-hack freshclam */ _snprintf(command, sizeof(command)-1, "freshclam.exe --update-db=custom --quiet --config-file=\"%s\\freshclam.conf\" --datadir=\"%s\"", datadir, datadir); command[sizeof(command)-1] = '\0'; memset(&sinfo, 0, sizeof(sinfo)); sinfo.cb = sizeof(sinfo); sinfo.dwFlags = STARTF_FORCEOFFFEEDBACK; if(!CreateProcess(NULL, command, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, datadir, &sinfo, &pinfo)) { flog("ERROR: failed to execute '%s'", command); SENDFAIL_AND_QUIT(UPD_CHECK); } CloseHandle(pinfo.hThread); if(WaitForSingleObject(pinfo.hProcess, 60*1000) == WAIT_TIMEOUT) { TerminateProcess(pinfo.hProcess, 1338); flog("ERROR: timeout waiting for custom freshclam"); SENDFAIL_AND_QUIT(UPD_CHECK); } if(!GetExitCodeProcess(pinfo.hProcess, &dw)) { CloseHandle(pinfo.hProcess); flog("ERROR: failed to retrieve custom freshclam return code"); SENDFAIL_AND_QUIT(UPD_CHECK); } CloseHandle(pinfo.hProcess); if(dw == 0) customok = 1; else flog("INFO: custom freshclam return code: %u", dw); /* Early exit for custom only */ if(customonly) { if(dw == 0) SENDMSG_AND_RETURN(UPD_DONE, dw); else SENDMSG_AND_RETURN(UPD_ABORT, dw); } /* Make pipe for freshclam stdio */ if(!CreatePipe(&cld_r, &cld_w, NULL, 0)) { flog("ERROR: failed to create pipe"); SENDFAIL_AND_QUIT(UPD_CHECK); } if(!DuplicateHandle(GetCurrentProcess(), cld_w, GetCurrentProcess(), &cld_w2, 0, TRUE, DUPLICATE_SAME_ACCESS)) { CloseHandle(cld_r); CloseHandle(cld_w); flog("ERROR: failed to duplicate pipe"); SENDFAIL_AND_QUIT(UPD_CHECK); } CloseHandle(cld_w); /* init my_fgets */ init_myf(&spam, cld_r); /* Redir freshclam stdio */ memset(&sinfo, 0, sizeof(sinfo)); sinfo.cb = sizeof(sinfo); sinfo.hStdInput = GetStdHandle(STD_INPUT_HANDLE); sinfo.hStdOutput = cld_w2; sinfo.hStdError = cld_w2; sinfo.dwFlags = STARTF_FORCEOFFFEEDBACK|STARTF_USESTDHANDLES; /* Run main freshclam */ _snprintf(command, sizeof(command)-1, "freshclam.exe --stdout --config-file=\"%s\\freshclam.conf\" --datadir=\"%s\"%s", datadir, datadir, mindefs ? " --update-db=daily" : ""); command[sizeof(command)-1] = '\0'; if(!CreateProcess(NULL, command, NULL, NULL, TRUE, DETACHED_PROCESS, NULL, datadir, &sinfo, &pinfo)) { CloseHandle(cld_w2); CloseHandle(cld_r); flog("ERROR: failed to execute '%s'", command); SENDFAIL_AND_QUIT(UPD_CHECK); } st.pid = pinfo.dwProcessId; CloseHandle(pinfo.hThread); CloseHandle(cld_w2); flog_dbg("Executing '%s'", command); /* Create STOP watcher */ if(!CreateThread(NULL, 0, watch_stop, NULL, 0, &dw)) { flog("ERROR: failed to create watch_stop thread"); CloseHandle(cld_r); CloseHandle(pinfo.hProcess); SENDFAIL_AND_QUIT(UPD_CHECK); } log_state(fstate); /* Spam parsing */ while(1) { char *buf; buf = my_fgets(&spam); flog_dbg("GOT: %s", buf); if(!buf) break; if(fstate == FRESH_PRE && !strncmp(buf, FRESH_PRE_START_S, sizeof(FRESH_PRE_START_S)-1)) { SENDOK(UPD_CHECK); fstate = FRESH_IDLE; log_state(fstate); continue; } if((fstate == FRESH_IDLE || fstate == FRESH_DOWN) && !strncmp(buf, FRESH_DOWN_S, sizeof(FRESH_DOWN_S)-1)) { unsigned int pct, fnamelen; char *partname = buf + 12, *partend, *pctend; wchar_t nuname[AV_UPD_FILE_NAME_MAX]; if(!updated_files) { SENDOK(UPD_NEWER_FOUND); SENDOK(UPD_DOWNLOAD_BEGIN); } updated_files++; partend = strchr(partname, ' '); if(!partend) break; *partend = '\0'; fnamelen = partend - partname; partend = strchr(partend + 1, '['); if(!partend) break; partend++; pct = strtol(partend, &pctend, 10); if(pctend == partend || *pctend != '%') break; fnamelen = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, partname, (fnamelen < AV_UPD_FILE_NAME_MAX-1) ? fnamelen : AV_UPD_FILE_NAME_MAX-1, nuname, sizeof(nuname)); if(!fnamelen) break; nuname[fnamelen] = L'\0'; if(fstate == FRESH_DOWN && wcscmp(nuname, st.fileName)) { st.percentDownloaded = 100; SENDOK(UPD_FILE_COMPLETE); fstate = FRESH_IDLE; log_state(fstate); } if(fstate == FRESH_IDLE) { wcscpy(st.fileName, nuname); st.percentDownloaded = 0; SENDOK(UPD_FILE_BEGIN); fstate = FRESH_DOWN; log_state(fstate); } st.percentDownloaded = pct; SENDOK(UPD_FILE_PROGRESS); continue; } if(fstate == FRESH_IDLE) { if(strstr(buf, FRESH_UPTODATE_S)) continue; if(!strncmp(buf, FRESH_DONE_S, sizeof(FRESH_DONE_S) - 1)) { fstate = FRESH_RELOAD; log_state(fstate); continue; } } if(fstate == FRESH_DOWN) { if(!strcmp(buf, FRESH_DOWN_FAIL_S)) { flog("ERROR: sigcheck verification failed"); #if 0 // FIXME: ask prashant send_pipe(&st, UPD_FILE_COMPLETE, 1); #else SENDOK(UPD_FILE_COMPLETE); #endif fstate = FRESH_IDLE; log_state(fstate); continue; } if(strstr(buf, FRESH_UPDATED_S)) { SENDOK(UPD_FILE_COMPLETE); fstate = FRESH_IDLE; log_state(fstate); continue; } if(strlen(buf) > sizeof(FRESH_DOWN_S)-1 && strstr(buf, FRESH_DOWN_S)) continue; } } CloseHandle(cld_r); WaitForSingleObject(pinfo.hProcess, 30*1000); if(!GetExitCodeProcess(pinfo.hProcess, &dw)) { CloseHandle(pinfo.hProcess); flog("ERROR: failed to retrieve freshclam return code"); SENDFAIL_AND_QUIT(UPD_ABORT); } CloseHandle(pinfo.hProcess); if(dw) { if(dw == STILL_ACTIVE) { flog("WARNING: freshclam didn't exit, killing it..."); kill_freshclam(); } else flog("ERROR: freshclam exit code %u", dw); if(st.state == UPD_CHECK) st.state = UPD_ABORT; SENDMSG_AND_RETURN(st.state, dw); } if((updated_files && fstate != FRESH_RELOAD) || (!updated_files && fstate != FRESH_IDLE)) { flog("ERROR: log parse failure. Freshclam exit value: %u", dw); SENDFAIL_AND_QUIT(st.state); } /* Send complete fin seq */ if(updated_files) { SENDOK(UPD_DOWNLOAD_COMPLETE); SENDOK(UPD_INSTALL_BEGIN); SENDOK(UPD_INSTALL_COMPLETE); SENDOK(UPD_DONE); } else SENDOK(UPD_NONE); CloseHandle(updpipe); CloseHandle(write_event); flog_close(); return 0; }
void sub_write(char *arg, char_data *ch, byte find_invis, int targets) { char str[MAX_INPUT_LENGTH * 2]; char type[MAX_INPUT_LENGTH], name[MAX_INPUT_LENGTH]; char *tokens[MAX_INPUT_LENGTH], *s, *p; void *otokens[MAX_INPUT_LENGTH]; char_data *to; obj_data *obj; int i, tmp; int to_sleeping = 1; /* mainly for windows compiles */ if (!arg) return; tokens[0] = str; for (i = 0, p = arg, s = str; *p;) { switch (*p) { case '~': case '@': case '^': case '&': case '*': /* get char_data, move to next token */ type[i] = *p; *s = '\0'; p = any_one_name(++p, name); /* 20-10-15 changed the following line due to compiler error (char_data *)otokens[i] = */ otokens[i] = find_invis ? get_char(name) : get_char_room_vis(ch, name); tokens[++i] = ++s; break; case '`': /* get obj_data, move to next token */ type[i] = *p; *s = '\0'; p = any_one_name(++p, name); /* 20-10-2015 updated following line due to compiler errors (obj_data *)otokens[i] = */ otokens[i] = (void*) find_invis ? (obj = get_obj(name)) : ((obj = get_obj_in_list_vis(ch, name, world[IN_ROOM(ch)].contents)) ? obj : (obj = get_object_in_equip_vis(ch, name, ch->equipment, &tmp)) ? obj : (obj = get_obj_in_list_vis(ch, name, ch->carrying))); /* 20-10-15 Updated the following line due to comp error (obj_data *)otokens[i] = obj; */ otokens[i] = (void*) obj; tokens[++i] = ++s; break; case '\\': p++; *s++ = *p++; break; default: *s++ = *p++; } } *s = '\0'; tokens[++i] = NULL; if (IS_SET(targets, TO_CHAR) && SENDOK(ch)) sub_write_to_char(ch, tokens, otokens, type); if (IS_SET(targets, TO_ROOM)) for (to = world[IN_ROOM(ch)].people; to; to = to->next_in_room) if (to != ch && SENDOK(to)) sub_write_to_char(to, tokens, otokens, type); }
void sub_write(char *arg, char_data *ch, byte find_invis, int targets) { char str[MAX_INPUT_LENGTH * 2]; char type[MAX_INPUT_LENGTH], name[MAX_INPUT_LENGTH]; char *tokens[MAX_INPUT_LENGTH], *s, *p; void *otokens[MAX_INPUT_LENGTH]; char_data *to; obj_data *obj; int i, tmp; int to_sleeping = 1; /* mainly for windows compiles */ if (!arg) return; tokens[0] = str; for (i = 0, p = arg, s = str; *p;) { switch (*p) { case '~': case '|': case '^': case '&': case '*': /* get char_data, move to next token */ type[i] = *p; *s = '\0'; p = any_one_name(++p, name); otokens[i] = find_invis ? (void *)get_char_in_room(&world[IN_ROOM(ch)], name) : (void *)get_char_room_vis(ch, name, NULL); tokens[++i] = ++s; break; case '`': /* get obj_data, move to next token */ type[i] = *p; *s = '\0'; p = any_one_name(++p, name); if (find_invis) obj = get_obj_in_room(&world[IN_ROOM(ch)], name); else if (!(obj = get_obj_in_list_vis(ch, name, NULL, world[IN_ROOM(ch)].contents))) ; else if (!(obj = get_obj_in_equip_vis(ch, name, &tmp, ch->equipment))) ; else obj = get_obj_in_list_vis(ch, name, NULL, ch->carrying); otokens[i] = (void *)obj; tokens[++i] = ++s; break; case '\\': p++; *s++ = *p++; break; default: *s++ = *p++; } } *s = '\0'; tokens[++i] = NULL; if (IS_SET(targets, TO_CHAR) && SENDOK(ch)) sub_write_to_char(ch, tokens, otokens, type); if (IS_SET(targets, TO_ROOM)) for (to = world[IN_ROOM(ch)].people; to; to = to->next_in_room) if (to != ch && SENDOK(to)) sub_write_to_char(to, tokens, otokens, type); }