Example #1
0
static int intarg (char * op) {
  const char * tok;
  if (!(tok = strtok (0, " ")) || !isnumstr (tok) || strtok (0, " ")) {
    perr ("expected integer argument for '%s'", op);
    exit (1);
  }
  return atoi (tok);
}
Example #2
0
static void
parse_cmd_line_options (QDPLLApp * app, QDPLL * qdpll, int argc, char **argv)
{
  char *result;
  int opt_cnt;
  for (opt_cnt = 1; opt_cnt < argc; opt_cnt++)
    {
      char *opt_str = argv[opt_cnt];

      if (!strcmp (opt_str, "-h") || !strcmp (opt_str, "--help"))
        {
          app->options.print_usage = 1;
        }
      else if (!strcmp (opt_str, "--version"))
        {
          app->options.print_version = 1;
        }
      else if (!strcmp (opt_str, "--pretty-print"))
        {
          app->options.pretty_print = 1;
        }
      else if (!strcmp (opt_str, "--qdo"))
        {
          app->options.qdimacs_output = 1;
        }
      else if (!strcmp (opt_str, "--deps-only"))
        {
          app->options.deps_only = 1;
        }
      else if (!strcmp (opt_str, "--print-deps"))
        {
          app->options.print_deps = 1;
        }
      else if (!strcmp (opt_str, "--dump-dep-graph"))
        {
          app->options.dump_dep_graph = 1;
        }
      else if (!strcmp (opt_str, "--qdag-print-deps-by-search"))
        {
          app->options.print_deps = 1;
          if ((result = qdpll_configure (qdpll, opt_str)))
            print_abort_err (app, "%s!\n\n", result);
        }
      else if (!strcmp (opt_str, "--trace")
               || !strcmp (opt_str, "--trace=qrp"))
        {
          app->options.trace = TRACE_QRP;
          qdpll_configure (qdpll, opt_str);
        }
      else if (!strcmp (opt_str, "--trace=bqrp"))
        {
          app->options.trace = TRACE_BQRP;
          qdpll_configure (qdpll, opt_str);
        }
      else if (isnumstr (opt_str))
        {
          app->options.max_time = atoi (opt_str);
          if (app->options.max_time == 0)
            {
              result = "Expecting non-zero value for max-time";
              print_abort_err (app, "%s!\n\n", result);
            }
        }
      else if (!strncmp (opt_str, "-", 1) || !strncmp (opt_str, "--", 2))
        {
          /* Handle QDPLL-options. */
          if (!strcmp (opt_str, "-v"))
            {
              app->options.verbosity++;
            }
          if ((result = qdpll_configure (qdpll, opt_str)))
            print_abort_err (app, "%s!\n\n", result);
        }
      else if (!app->options.in_filename)
        {
          app->options.in_filename = opt_str;
          /* Check input file. */
          DIR *dir;
          if ((dir = opendir (app->options.in_filename)) != NULL)
            {
              closedir (dir);
              print_abort_err (app, "input file '%s' is a directory!\n\n",
                               app->options.in_filename);
            }
          FILE *input_file = fopen (app->options.in_filename, "r");
          if (!input_file)
            {
              print_abort_err (app, "could not open input file '%s'!\n\n",
                               app->options.in_filename);
            }
          else
            app->options.in = input_file;
        }
      else
        {
          print_abort_err (app, "unknown option '%s'!\n\n", opt_str);
        }
    }
}
Example #3
0
void HandleCmdReq(PLUSER pluser, char *text, int index) {
	char asdf[256], sdfg[256], timestamp[16], tmpuser[32];
	char *tosend, *bigmem;
	int cmdi, i;
	time_t rawtime;
	void *timeinfo;
	void (*InviteResponse)(int, int);
	LPCHUSER pchuser;
	PLUSER tmppluser;
	char *temp, *arg2, chr;

	if ((gstate & GFS_LOCKED) && (pluser->access <= 100))
		return;

	temp = strchr(text, ' ');
	if (temp) {
		*temp++ = 0;
		if ((pluser->access >= 100) && isnumstr(text)) {
			QueueAdd(temp, atoi(text));
			return;
		}
	}

	lcase(text); //// justified
	cmdi = CmdGetIndex(hash((unsigned char *)text));
	if (cmdi == -1 || strcmp(text, cmddesc[cmdi].string)) {
		if (pluser->access == 103)
			printf("\'%s\' invalid command!\n", text);
		return;
	}
    if (pluser->access < cmddesc[cmdi].access)
        return;

	tosend = NULL;
	bigmem = NULL;
	switch (cmdi) {
		case CMD_V:
		case CMD_VER:
		case CMD_VERSION:
            //*(int32_t *)0 = 0; ///for crash handle testing
			GetOS(sdfg);
			sprintf(asdf, pluser->access == 103 ?
				"Phyros " BOT_VER "  [ %s ]" :
				"/me : : : Phyros " BOT_VER "  [ %s ] : : : ", sdfg);
			tosend = asdf;
			break;
		case CMD_SAY:
			if (pluser->access < 100)
				*(--temp) = ' ';
			tosend = temp;
			break;
		case CMD_RUN:
		case CMD_LOUD:
            if (temp)
                _CreateThread(RunLoudProc, temp);
			break;
		case CMD_RUNQUIET:
		case CMD_QUIET:
            if (temp)
                _CreateThread(RunQuietProc, temp);
			break;
		case CMD_B:
		case CMD_BAN:
			HandleBUKUserCmd(pluser, temp, BTYPE_FBAN, index);
			break;
		case CMD_UU:
			sprintf(asdf, "/w %s You have been unbanned from %s.",
				temp, curchan);
			tosend = asdf;
		case CMD_UNBAN:
		case CMD_U:
			HandleBUKUserCmd(pluser, temp, BTYPE_UNBAN, index);
			break;
		case CMD_K:
		case CMD_KICK:
			HandleBUKUserCmd(pluser, temp, BTYPE_KICK, index);
			break;
		case CMD_A:
		case CMD_ACCESS:
		case CMD_WHOIS:
		case CMD_WHOAMI:
			if ((cmdi != CMD_WHOIS) && (!temp)) {
				tmppluser = pluser;
			} else {
				if (!temp) {
					tosend = asdf;
					break;
				}
				lcase(temp); /////justified
				RealmFix(temp, tmpuser, 0); //////ermm, is this a regression?
				tmppluser = HtGetItem(tmpuser, lusers, TL_LUSERS);
			}
			if (tmppluser)
				sprintf(asdf, "%s :: %d access", tmppluser->username, tmppluser->access);
			else
				sprintf(asdf, "%s not found in access database.", tmpuser);
			tosend = asdf;
			break;
		case CMD_CMDACCESS:
		case CMD_HELP:
			if (temp) {
				lcase(temp); ////justified
				i = CmdGetIndex(hash((unsigned char *)temp));
				if (i == -1 || strcmp(temp, cmddesc[i].string)) {
					sprintf(asdf, "Command \'%s\' does not exist.", temp);
					tosend = asdf;
				} else {
					if (cmdi == CMD_CMDACCESS) {
						sprintf(asdf, "Command \'%s\' requires %d access.",
							temp, cmddesc[i].access);
						tosend = asdf;
					} else {
						tosend = HelpLookupCmdStr(i);
					}
				}
				tosend = asdf;
			}
			break;
		case CMD_CMDS:
			for (i = 0; i != ARRAYLEN(cmddesc); i++) {
				if (!temp || WildcardMatch(temp, cmddesc[i].string)) {
					printf("%s - access required: %d - %s",
						cmddesc[i].string, cmddesc[i].access, HelpLookupCmdUsage(i));
				}
			}
			break;
		case CMD_ADD:
			*asdf = 0;
			HandleAddUserCmd(pluser, temp, asdf);
			if (*asdf)
				tosend = asdf;
			break;
		case CMD_REM:
			*asdf = 0;
            HandleRemoveUserCmd(pluser, temp, asdf);
			if (*asdf)
				tosend = asdf;
			break;
		case CMD_USERS:
			bigmem = HandleUsersCmd();
			tosend = bigmem;
			break;
		case CMD_BL:
		case CMD_BLACKLIST:
			tosend = HandleBlacklistCmd(pluser, temp, asdf);
			if (!tosend)
				tosend = asdf;
			else
				bigmem = tosend;
			break;
		case CMD_SHITADD:
		case CMD_SA:
			chr = 'S';
			goto over_ta;
		case CMD_TAGADD:
		case CMD_TA:
			chr = 'T';
		over_ta:
			arg2 = strchr(temp, ' ');
			if (arg2)
				*arg2++ = 0;
			BlacklistAddToDB(text, chr, pluser->username, arg2, asdf);
			tosend = asdf;
			break;
		case CMD_SHITDEL:
		case CMD_SD:
			chr = 'S';
			goto over_td;
		case CMD_TAGDEL:
		case CMD_TD:
			chr = 'T';
		over_td:
			BlacklistRemoveFromDB(text, chr, asdf);
			tosend = asdf;
			break;
		case CMD_IPBAN:
		case CMD_IP:
			HandleBUKUserCmd(pluser, temp, BTYPE_IPBAN, index);
			break;
		case CMD_UNIPBAN:
		case CMD_UNIP:
			HandleBUKUserCmd(pluser, temp, BTYPE_UNIP, index);
			break;
		case CMD_SWEEP: // also add a wakechannel command to send everybody's name
		case CMD_SB:    // sweep IDLE command (compare everybody in channel who didn't talk and kick)
			tosend = SweepStart(temp, asdf);
			break;
		case CMD_IPSWEEP:
			break;
		case CMD_IDLESWEEP:
			break;
		case CMD_P:
		case CMD_PING:
			if (temp) {
				if (*(int16_t *)temp == 's/') {
					Send0x15(index);
					break;
				} else {
					lcase(temp); //// justified
					RealmFix(temp, tmpuser, 0);
					pchuser = HtGetItem(tmpuser, users, TL_BNUSERS);
				}
			} else {
				pchuser = HtGetItem((pluser->access == 103) ?
					bot[curbotinc()]->realname : pluser->username, users, TL_BNUSERS);
			}
			if (pchuser) {
				sprintf(asdf, "%s's ping is %ums.", pchuser->username, pchuser->ping);
				tosend = asdf;
			} else {
				tosend = "Specified user cannot be found.";
			}
			break;
		case CMD_BANCOUNT:
			sprintf(asdf, "%u users have been banned.", bancount);
			tosend = asdf;
			break;
		case CMD_BANNED:
			bigmem = HandleBannedCmd();
			tosend = bigmem;
			break;
		case CMD_J:
		case CMD_JOIN:
			sprintf(asdf, "/j %s", temp);
			tosend = asdf;
			break;
		case CMD_FJOIN:
		case CMD_FORCEJOIN:
		case CMD_FJ:
			InsertDWORD(0x02);
			InsertNTString(temp);
			SendPacket(0x0C, index);
			break;
		case CMD_HOME:
			sprintf(asdf, "/j %s", home);
			tosend = asdf;
			break;
		case CMD_CLOSE:
		case CMD_EXIT:
		case CMD_QUIT:
			exit(1);
			break;
		case CMD_LEAVE:
			SendPacket(0x10, index);
			break;
		case CMD_DAEMON:
		case CMD_HIDE:
			#ifdef _WIN32
				ShowWindow(GetConsoleWindow(), SW_HIDE);
			#else

			#endif
			break;
		case CMD_SHOW:
			#ifdef _WIN32
				ShowWindow(GetConsoleWindow(), SW_SHOW);
			#else

			#endif
			break;
		case CMD_CONNECT:
			if (temp) {
				i = atoi(temp);
				if (i < 0 || i >= numbots)
					break;
				ConnectBot(i);
			} else {
				for (i = 0; i != numbots; i++) {
					if (!bot[i]->connected) {
						ConnectBot(i);
						break;
					}
				}
			}
			break;
		case CMD_DISCONNECT:
			if (temp) {
				i = atoi(temp);
				if (i < 0 || i >= numbots)
					break;
				DisconnectBot(i, DISCN_GRACEFUL);
			}
			break;
		case CMD_RC:
		case CMD_RECONNECT:
			if (temp) {
				i = atoi(temp);
				if (i < 0 || i >= numbots)
					break;
				DisconnectBot(i, DISCN_GRACEFUL);
				ConnectBot(i);
			}
			break;
		case CMD_UPTIME:
			tosend = HandleUptimeCmd(asdf, temp, index);
			break;
		case CMD_CQ:
			cmdi = 0;
			for (i = 0; i != numbots; i++)
				cmdi += bot[i]->queue.count;
			sprintf(asdf, "Cleared %d queued items.", cmdi);
			tosend = asdf;
		case CMD_SCQ:
			QueueClearAll();
			break;
		case CMD_CBQ:
		case CMD_SCBQ:

			break;
		case CMD_LW:
		case CMD_LASTWHISPER:
			if (lastwhisper.profile != -1) {
				sprintf(asdf, "Last whisper to profile %d was sent by %s: %s",
					lastwhisper.profile, lastwhisper.user, lastwhisper.message);
				tosend = asdf;
			} else {
				tosend = "No whispers received!";
			}
			break;
		case CMD_DATE:
		case CMD_TIME:
			time(&rawtime);
			timeinfo = (void *)localtime(&rawtime);
			strftime(asdf, sizeof(asdf),
				(cmdi == CMD_DATE) ? "%m/%d/%Y" : "%I:%M:%S %p",
				(void *)timeinfo);
			tosend = asdf;
			break;
		case CMD_MOTD:
			if (pluser->access != 103)
				bot[index]->fstate |= BFS_EXTERNALREQ;
			InsertDWORD(0x3713);
			SendPacket(0x7C, index);
			break;
		case CMD_SETMOTD:
			if (temp) {
				sprintf(asdf, "/c motd %s", temp);
				QueueAdd(asdf, index);
			}
			break;
		case CMD_CLAN:
			if (pluser->access != 103)
				bot[index]->fstate |= BFS_EXTERNALREQ;
			Send0x7D(index);
			break;
		case CMD_CRANK:
			if (pluser->access != 103)
				bot[index]->fstate |= BFS_EXTERNALREQ;
			if (temp) {
				arg2 = strchr(temp, ' ');
				if (arg2) {
					*arg2++ = 0;
					Send0x7A(temp, (unsigned char)atoi(arg2), index);
				}
			}
			break;
		case CMD_INVITE:
			if (temp) {
				if (pluser->access != 103)
					bot[index]->fstate |= BFS_EXTERNALREQ;
				Send0x77(temp, index);
			}
			break;
		case CMD_TINVITES:
			ToggleGlobalFlag(temp, GFS_ACCEPTINVS, asdf, 
				"%sing invintation requests.", "Accept", "Ignor");
			tosend = asdf;
			break;
		case CMD_ACCEPT:
		case CMD_DECLINE:
			if (!bot[index]->invited.tag) {
				tosend = "No pending invitations.";
			} else {
				InviteResponse = (bot[index]->fstate & BFS_CREATEINV) ? Send0x72 : Send0x79;
				(*InviteResponse)((cmdi == CMD_ACCEPT) ? 'y' : 'n', temp ? atoi(temp) : index);
				sprintf(asdf, "%sed clan invitation.", (cmdi == CMD_ACCEPT) ? "Accept" : "Declin");
				tosend = asdf;
			}
			break;
		case CMD_DP:
			break;
		case CMD_DDP:
			break;
		case CMD_CP:
			break;
		case CMD_AUTOCP:
			break;
		case CMD_GREET:
			break;
		case CMD_IDLE:
			break;
		case CMD_HALT:
			if (temp) {
				//lcase(temp);
				tmppluser = HtGetItem(temp, lusers, TL_LUSERS);
				if (tmppluser) {
					if (tmppluser->access < pluser->access) {
						if (tmppluser->flags & LUR_HALTED) {
							tmppluser->access = tmppluser->oacces;
							tmppluser->flags &= ~LUR_HALTED;
						} else {
							tmppluser->oacces = tmppluser->access;
							tmppluser->access = 1;
							tmppluser->flags |= LUR_HALTED;
							
						}
						sprintf(asdf, "User \'%s\' has been %shalted.", temp, 
							(tmppluser->flags & LUR_HALTED) ? "" : "un");
						tosend = asdf;
					}
				}
			}
			break;
		case CMD_SETTRIGGER:
			if (temp) {
				sprintf(asdf, "Trigger has been changed from \'%c\' to \'%c\'.",
					bot[index]->trigger, *temp);
				bot[index]->trigger = *temp;
				tosend = asdf;
			}
			break;
		case CMD_IGNPUB:
			if (temp) {					   
				temp = (((*(int16_t *)temp) | 0x2020) == 'on') ? "/o igpub" : "/o unigpub";
				for (i = 1; i != numbots; i++) {
					if (bot[i]->connected)
						QueueAdd(temp, i);
				} ///////////////make it per profile, add ignpriv
			}
			break;
		case CMD_CLIENTBAN:
			//SetFlagAndValue(temp, GFS_CLIENTBAN, &clientban, asdf);
			break;
		case CMD_PHRASE:
		case CMD_PB: ////phraseban alias
		case CMD_PHRASEBAN:
			HandlePhraseCmd(pluser, temp, asdf);
			break;
		case CMD_PHRASEADD:
			break;
		case CMD_PHRASEDEL:
			break;
		case CMD_PINGBAN:
			break;
		case CMD_PLUGBAN:
			break;
		case CMD_INDEXBAN:
			break;
		case CMD_BANEVASION:
			break;
		case CMD_NUMBERSBAN:
			break;
		case CMD_ALTCAPSBAN:
			break;
		case CMD_BANNING:
			break;
		case CMD_LOADBAN:
			break;
		case CMD_WINBAN:
			SetFlagAndValue(temp, GFS_WINBAN, &ban_winlow, asdf,
				"Winban set to %d.", "Winban disabled.");
			tosend = asdf;
			break;
		case CMD_AUTOLOAD:
			break;
		case CMD_DESIGNATE:
		case CMD_OP:
			if (temp) {
				RealmFix(temp, tmpuser, 0);
				sprintf(asdf, "/designate %s", tmpuser);
			} else {
				sprintf(asdf, "/designate %s", pluser->username);
			}  
			QueueAdd(asdf, index);
			if (cmdi == CMD_OP)
				RejoinChannel(index);
			break;
		case CMD_LOCKDOWN:
			break;
		case CMD_MASS:
			sprintf(asdf, "/j %s", temp);
			for (i = 0; i != numbots; i++)
				QueueAdd(asdf, i);
			break;
		case CMD_RJ:
			RejoinChannel(index);
			break;
		case CMD_PROFILES:
			bigmem = HandleProfilesCmd();
			tosend = bigmem;
			break;				   
		case CMD_SETNAME:
			if (temp) {
				arg2 = strchr(temp, ' ');
				i = arg2 ? atoi(arg2 + 1) : 0;
				strncpy(bot[i]->username, temp, sizeof(bot[i]->username));
				bot[i]->username[sizeof(bot[i]->username) - 1] = 0;
				sprintf(asdf, "Set new username for profile %d to %s.",
					i, bot[i]->username);
				tosend = asdf; ///////////////////////////////////
			}
			break;
		case CMD_SETPASS:
			if (temp) {
				arg2 = strchr(temp, ' ');
				i = arg2 ? atoi(arg2 + 1) : 0;
				strncpy(bot[i]->password, temp, sizeof(bot[i]->password));
				bot[i]->password[sizeof(bot[i]->password) - 1] = 0;
				sprintf(asdf, "Set new password for profile %d.", i);
				tosend = asdf; /////////////////set permanently in config!
			}
			break;
		case CMD_RELOAD:
			tosend = HandleReloadCmd(temp);
			break;
		case CMD_CREMOVE:
			if (pluser->access != 103)
				bot[index]->fstate |= BFS_EXTERNALREQ;
			Send0x78(temp, index);
			break;
		case CMD_CHIEFTAIN:
			if (temp) {
				if (pluser->access != 103)
					bot[index]->fstate |= BFS_EXTERNALREQ;
				Send0x74(temp, index);
			}
			break;
		case CMD_MI:
		case CMD_MEMBERINFO:
			if (temp) {	//weird, i never get a response...
				//if (pluser->access != 103)
				//	bot[index]->fstate |= BFS_EXTERNALREQ;
				Send0x82(temp, index);
			}
			break;
		case CMD_CREATE:
			tosend = HandleClanCreateCommand(temp, index);
			break;
		case CMD_CHECKCLAN:
			if (temp) ////////////////////what about external requests?
				Send0x70(temp, index);
			break;
		case CMD_LOCK:
			ToggleGlobalFlag(temp, GFS_LOCKED, asdf,
				"Access has been %slocked.", "", "un");
			tosend = asdf;
			break;
		case CMD_LOGGING:
			ToggleGlobalFlag(temp, GFS_LOGGING, asdf,
				"Logging %sabled.", "en", "dis");
			tosend = asdf;
			break;
		case CMD_DISBAND:
			InsertDWORD(0x3713);
			SendPacket(0x73, index);
			break;
		case CMD_ERASE:
			tosend = HandleEraseCmd(temp);
			break;
		case CMD_PLGLOAD:
			break;
		case CMD_PLGSTAT:
			break;
		case CMD_PLGUNLOAD:
			break;
		case CMD_UPDATE:
			break;
		default:
			printf("Invalid command index %d (unimplemented)!\n", cmdi);
	}
	if (tosend) {
		if (pluser->access == 103) {
			GetTimeStamp(timestamp);
			printf("%s %s\n", timestamp, tosend);
		} else {
			QueueAdd(tosend, index);
		}
	}
	if (bigmem)
		free(bigmem);
}