Beispiel #1
0
void	bgoing(conn_t *conn, const char *buddy) {
	buddywin_t	*bwin = conn->curbwin;
	buddylist_t	*blist = NULL;

	assert(buddy != NULL);

	if (bwin == NULL)
		return;

	if ((blist = rgetlist(conn, buddy)) != NULL) {
		if ((blist->peer <= 0) && (blist->crypt != NULL))
			echof(conn, NULL, "Strangeness while marking %s offline: no autopeer negotiated, but autocrypt set!\n",
				buddy);
		blist->docrypt = blist->peer = 0;
		if (blist->crypt != NULL) {
			free(blist->crypt);
			blist->crypt = NULL;
		}
		if (blist->tzname != NULL) {
			free(blist->tzname);
			blist->tzname = NULL;
		}

		status_echof(conn, "<font color=\"#00FFFF\">%s</font> <font color=\"#800000\">[<B>%s</B>]</font> has just logged off :(\n", 
			user_name(NULL, 0, conn, blist), USER_GROUP(blist));
		blist->offline = 1;
		blist->warnval = blist->typing = blist->isadmin = blist->ismobile = blist->isidle = blist->isaway = 0;
	} else
		return;

	do {
		if ((bwin->et == BUDDY) && (firetalk_compare_nicks(conn->conn, buddy, bwin->winname) == FE_SUCCESS)) {
			int	autoclose = getvar_int(conn, "autoclose"),
				beeponsignon = getvar_int(conn, "beeponsignon");

			assert(bwin->e.buddy == blist);
			window_echof(bwin, "<font color=\"#00FFFF\">%s</font> <font color=\"#800000\">[<B>%s</B>]</font> has just logged off :(\n",
				user_name(NULL, 0, conn, blist), USER_GROUP(blist));
			if ((beeponsignon > 1) || ((awaytime == 0) && (beeponsignon == 1)))
				beep();
			FREESTR(bwin->blurb);
			FREESTR(bwin->status);

			if (bwin->keepafterso == 1) {
				if ((autoclose > 0) && !USER_PERMANENT(bwin->e.buddy) && (bwin->waiting == 0))
					bwin->closetime = now + 60*autoclose;
			} else {
				/* assert(bwin->waiting == 0); */
				bclose(conn, bwin, 1);
				bwin = NULL;
				if ((autoclose > 0) && !USER_PERMANENT(blist)) {
					rdelbuddy(conn, buddy);
					firetalk_im_remove_buddy(conn->conn, buddy);
				}
			}
			bupdate();
			return;
		}
	} while ((bwin = bwin->next) != conn->curbwin);
}
Beispiel #2
0
static int bsort_alpha_winname(const void *p1, const void *p2) {
	register buddywin_t
		**bw1 = (buddywin_t **)p1,
		**bw2 = (buddywin_t **)p2;
	char	b1[256], b2[256];
	register const char
		*s1a, *s2a,
		*s1b = (*bw1)->winname,
		*s2b = (*bw2)->winname;
	int	ret;

	assert(bsort_conn != NULL);
	if ((*bw1)->et == BUDDY)
		s1a = user_name(b1, sizeof(b1), bsort_conn, (*bw1)->e.buddy);
	else
		s1a = (*bw1)->winname;
	if ((*bw2)->et == BUDDY)
		s2a = user_name(b2, sizeof(b2), bsort_conn, (*bw2)->e.buddy);
	else
		s2a = (*bw2)->winname;

	ret = strcasecmp(s1a, s2a);
	if (ret != 0)
		return(ret);
	ret = strcasecmp(s1b, s2b);
	return(ret);
}
Beispiel #3
0
struct name_list *get_list(const struct stat *st, acl_t acl)
{
	struct name_list *first = NULL, *last = NULL;
	acl_entry_t ent;
	int ret = 0;

	if (acl != NULL)
		ret = acl_get_entry(acl, ACL_FIRST_ENTRY, &ent);
	if (ret != 1)
		return NULL;
	while (ret > 0) {
		acl_tag_t e_type;
		const id_t *id_p;
		const char *name = "";
		int len;

		acl_get_tag_type(ent, &e_type);
		switch(e_type) {
			case ACL_USER_OBJ:
				name = user_name(st->st_uid, opt_numeric);
				break;

			case ACL_USER:
				id_p = acl_get_qualifier(ent);
				if (id_p != NULL)
					name = user_name(*id_p, opt_numeric);
				break;

			case ACL_GROUP_OBJ:
				name = group_name(st->st_gid, opt_numeric);
				break;

			case ACL_GROUP:
				id_p = acl_get_qualifier(ent);
				if (id_p != NULL)
					name = group_name(*id_p, opt_numeric);
				break;
		}
		name = xquote(name, "\t\n\r");
		len = strlen(name);
		if (last == NULL) {
			first = last = (struct name_list *)
				malloc(sizeof(struct name_list) + len + 1);
		} else {
			last->next = (struct name_list *)
				malloc(sizeof(struct name_list) + len + 1);
			last = last->next;
		}
		if (last == NULL) {
			free_list(first);
			return NULL;
		}
		last->next = NULL;
		strcpy(last->name, name);

		ret = acl_get_entry(acl, ACL_NEXT_ENTRY, &ent);
	}
	return first;
}
Beispiel #4
0
void	bcoming(conn_t *conn, const char *buddy) {
	buddywin_t	*bwin = NULL;
	buddylist_t	*blist = NULL;

	assert(buddy != NULL);

	if ((blist = rgetlist(conn, buddy)) == NULL) {
		status_echof(conn, "Adding %s to your buddy list due to sign-on.\n", buddy);
		blist = raddbuddy(conn, buddy, DEFAULT_GROUP, NULL);
	}
	STRREPLACE(blist->_account, buddy);
	if ((bwin = bgetwin(conn, buddy, BUDDY)) == NULL) {
		if (getvar_int(conn, "autoquery") != 0) {
			bnewwin(conn, buddy, BUDDY);
			bwin = bgetwin(conn, buddy, BUDDY);
			assert(bwin != NULL);
		}
	}
	assert((bwin == NULL) || (bwin->e.buddy == blist));

	if (blist->offline == 1) {
		blist->isadmin = blist->ismobile = blist->isidle = blist->isaway = blist->offline = 0;
		status_echof(conn, "<font color=\"#00FFFF\">%s</font> <font color=\"#800000\">[<B>%s</B>]</font> is now online =)\n",
			user_name(NULL, 0, conn, blist), USER_GROUP(blist));
		if (bwin != NULL) {
			window_echof(bwin, "<font color=\"#00FFFF\">%s</font> <font color=\"#800000\">[<B>%s</B>]</font> is now online =)\n",
				user_name(NULL, 0, conn, blist), USER_GROUP(blist));
			if (bwin->pouncec > 0) {
				int	i, pc = bwin->pouncec;

				for (i = 0; i < pc; i++) {
					window_echof(bwin, "Sending queued IM %i/%i [%s].\n",
						i+1, pc, bwin->pouncear[i]);
					naim_send_im(conn, bwin->winname,
						bwin->pouncear[i], 1);
				}
				bwin->pouncec -= pc;
				memmove(bwin->pouncear, bwin->pouncear+pc,
					bwin->pouncec*sizeof(*(bwin->pouncear)));
				bwin->pouncear = realloc(bwin->pouncear,
					bwin->pouncec*sizeof(*(bwin->pouncear)));
			}
		}

		{
			int	beeponsignon = getvar_int(conn, "beeponsignon");

			if ((beeponsignon > 1) || ((awaytime == 0) && (beeponsignon == 1)))
				beep();
		}
	}
	bupdate();
}
Beispiel #5
0
static void
	bclearall_bwin(conn_t *conn, buddywin_t *bwin, int force) {
	FREESTR(bwin->blurb);
	FREESTR(bwin->status);
	switch (bwin->et) {
	  case BUDDY:
		assert(bwin->e.buddy != NULL);
		if (bwin->e.buddy->offline == 0) {
			bwin->e.buddy->offline = 1;
			window_echof(bwin, "<font color=\"#00FFFF\">%s</font> <font color=\"#800000\">[<B>%s</B>]</font> is no longer available :/\n",
				user_name(NULL, 0, conn, bwin->e.buddy), USER_GROUP(bwin->e.buddy));
		}
		if (bwin->keepafterso == 0) {
			bclose(conn, bwin, 1);
			bwin = NULL;
			return;
		}
		break;
	  case CHAT:
		bwin->e.chat->isoper = 0;
		if (bwin->e.chat->offline == 0) {
			bwin->e.chat->offline = 1;
			window_echof(bwin, "Chat <font color=\"#00FFFF\">%s</font> is no longer available :/\n",
				bwin->winname);
		}
		break;
	  case TRANSFER:
		break;
	}
	if (force) {
		bclose(conn, bwin, 1);
		bwin = NULL;
	}
}
Beispiel #6
0
void BrowserNode::assign(int w) {
  if (!ro && (owner != w)) {
    QDir & dir = BrowserView::get_dir();
    BooL dummy;
    
    char * p = read_file(dir, filename, dummy);
    
    if (p != 0) {
      QString path = dir.absFilePath(filename);
      FILE * fp = fopen(path, "wb");
      
      if (fp != 0) {
	fprintf(fp, "format %d\n\"%s\"\n  revision %s\n",
		format, (const char *) text(TREE_COL), (const char *) text(REVISION_COL));
	
	if (!modifier_name.isEmpty())
	  fprintf(fp, "  modified_by %d \"%s\"\n", modifier_id, (const char *) modifier_name);
	
	if (w != -1) {
	  fprintf(fp, "  owner %d", w);
	  
	  if (w != 0) {
	    QString s = user_name(w);
	    
	    setText(OWNER_COL, QString::number(w));
	    setText(OWNERNAME_COL, s);
	    
	    if (! s.isEmpty())
	      fprintf(fp, " \"%s\"\n", (const char *) s);
	    else
	      fputs(" \"\"\n", fp);
	  }
	  else {
	    fputc('\n', fp);
	    
	    setText(OWNER_COL, "<protected>");
	    setText(OWNERNAME_COL, "");
	  }
	}
	else {
	  setText(OWNER_COL, "");
	  setText(OWNERNAME_COL, "");
	}
	
	fputs("  ", fp);
	
	int new_offset = (int) ftell(fp);
	
	fputs(p + offset, fp);
	fclose(fp);
	
	offset = new_offset;
	owner = w;
	repaint();
      }
      
      delete [] p;
    }
  }
}
Beispiel #7
0
void ProxyManager::GetCurrentProxyAuthentication() {
  LOG(TRACE) << "ProxyManager::GetCurrentProxyAuthentication";

  DWORD user_name_length = 0;
  BOOL success = ::InternetQueryOption(NULL,
                                       INTERNET_OPTION_PROXY_USERNAME,
                                       NULL,
                                       &user_name_length);
  if (user_name_length > 0) {
    std::vector<wchar_t> user_name(user_name_length);
    success = ::InternetQueryOption(NULL,
                                    INTERNET_OPTION_PROXY_USERNAME,
                                    &user_name[0],
                                    &user_name_length);
    this->current_socks_user_name_ = &user_name[0];
  }

  DWORD password_length = 0;
  success = ::InternetQueryOption(NULL,
                                  INTERNET_OPTION_PROXY_PASSWORD,
                                  NULL,
                                  &password_length);
  if (password_length > 0) {
    std::vector<wchar_t> password(password_length);
    success = ::InternetQueryOption(NULL,
                                    INTERNET_OPTION_PROXY_PASSWORD,
                                    &password[0],
                                    &password_length);
    this->current_socks_password_ = &password[0];
  }
}
Beispiel #8
0
void	bidle(conn_t *conn, const char *buddy, int isidle) {
	buddywin_t	*bwin = NULL;
	buddylist_t	*blist = NULL;

	assert(buddy != NULL);
	bwin = bgetwin(conn, buddy, BUDDY);
	if (bwin == NULL)
		blist = rgetlist(conn, buddy);
	else
		blist = bwin->e.buddy;
	assert(blist != NULL);

	if (bwin != NULL) {
		if ((isidle == 1) && (blist->isidle == 0))
			window_echof(bwin, "<font color=\"#00FFFF\">%s</font> is now idle.\n",
				user_name(NULL, 0, conn, blist));
		else if ((isidle == 0) && (blist->isidle == 1))
			window_echof(bwin, "<font color=\"#00FFFF\">%s</font> is no longer idle!\n",
				user_name(NULL, 0, conn, blist));
	}

	blist->isidle = isidle;
}
Beispiel #9
0
void	baway(conn_t *conn, const char *buddy, int isaway) {
	buddywin_t	*bwin = NULL;
	buddylist_t	*blist = NULL;

	assert(buddy != NULL);
	bwin = bgetwin(conn, buddy, BUDDY);
	if (bwin == NULL)
		blist = rgetlist(conn, buddy);
	else
		blist = bwin->e.buddy;
	assert(blist != NULL);

	if (bwin != NULL) {
		if (isaway == 0)
			FREESTR(bwin->blurb);
		if ((isaway == 1) && (blist->isaway == 0)) {
			if ((conn->online+30) < now) {
				awayc++;
				awayar = realloc(awayar, awayc*sizeof(*awayar));
				awayar[awayc-1].name = strdup(buddy);
				awayar[awayc-1].gotaway = 0;
				firetalk_im_get_info(conn->conn, buddy);
			} else
				window_echof(bwin, "<font color=\"#00FFFF\">%s</font> is now away.\n",
					user_name(NULL, 0, conn, blist));
		} else if ((isaway == 0) && (blist->isaway == 1)) {
			if (bwin->status != NULL)
				window_echof(bwin, "<font color=\"#00FFFF\">%s</font> is now available: %s\n",
					user_name(NULL, 0, conn, blist), bwin->status);
			else
				window_echof(bwin, "<font color=\"#00FFFF\">%s</font> is no longer away!\n",
					user_name(NULL, 0, conn, blist));
		}
	}

	blist->isaway = isaway;
}
Beispiel #10
0
/*
 * Initialise things for multiuser machines
 * Pay special attention to permisions.
 */
void init_setuid(void)
{
	/* Default permissions on files */
	(void)umask(022);

	/* Get the user id (?) */
	player_uid = getuid();

#ifdef VMS
	/* Mega-Hack -- Factor group id */
	player_uid += (getgid() * 1000);
#endif /* VMS */

#ifdef SAFE_SETUID

#if defined(HAVE_SETEGID) || defined(SAFE_SETUID_POSIX)

	/* Save some info for later */
	player_euid = geteuid();
	player_egid = getegid();

#endif /* defined(HAVE_SETEGID) || defined(SAFE_SETUID_POSIX) */

	/* XXX XXX XXX */
#if 0

	/* Redundant setting necessary in case root is running the game */
	/* If not root or game not setuid the following two calls do nothing */

	if (setgid(getegid()) != 0)
	{
		quit("setgid(): cannot set permissions correctly!");
	}

	if (setuid(geteuid()) != 0)
	{
		quit("setuid(): cannot set permissions correctly!");
	}

#endif /* 0 */

#endif /* SAFE_SETUID */

	/* Drop permissions */
	safe_setuid_drop();

	/* Get the "user name" as a default player name */
	user_name(player_name, player_uid);
}
int main(int argc, _TCHAR* argv[])
{

	Attribute user_id("user_id", "int");
	Attribute user_name("user_id", "string");
	Attribute privilege_level("user_id", "string");

	vector<Attribute> attributeList = { user_id, user_name, privilege_level };

	Table table(attributeList);

	vector<string> newRow = {"0","Bobby","admin"};

	table.pushBackRow(newRow);

	return 0;
}
Beispiel #12
0
Bool
pwent_priv_init (int argc, char **argv, Bool verbose_p)
{
  char *u;

#ifdef HAVE_ENHANCED_PASSWD
  set_auth_parameters(argc, argv);
  check_auth_parameters();
#endif /* HAVE_DEC_ENHANCED */

  u = user_name();
  encrypted_user_passwd = get_encrypted_passwd(u);
  encrypted_root_passwd = get_encrypted_passwd(ROOT);
  if (u) free (u);

  if (encrypted_user_passwd)
    return True;
  else
    return False;
}
Beispiel #13
0
/***********************************************************************//**
 * @brief Publish exposure cube
 *
 * @param[in] name Exposure cube name.
 ***************************************************************************/
void ctexpcube::publish(const std::string& name)
{
    // Write header into logger
    log_header1(TERSE, "Publish exposure cube");

    // Set default name if user name is empty
    std::string user_name(name);
    if (user_name.empty()) {
        user_name = CTEXPCUBE_NAME;
    }

    // Write exposure cube name into logger
    log_value(NORMAL, "Counts cube name", user_name);

    // Publish exposure cube
    m_expcube.cube().publish(user_name);

    // Return
    return;
}
/**
 * Updates the status (active/inactive) of an iam user's access key, based on
 * command line input
 */
int main(int argc, char** argv)
{
    if(argc != 4) {
        PrintUsage();
        return 1;
    }

    Aws::String user_name(argv[1]);
    Aws::String accessKeyId(argv[2]);

    auto status =
        Aws::IAM::Model::StatusTypeMapper::GetStatusTypeForName(argv[3]);

    if (status == Aws::IAM::Model::StatusType::NOT_SET) {
        PrintUsage();
        return 1;
    }

    Aws::SDKOptions options;
    Aws::InitAPI(options);

    {
        Aws::IAM::IAMClient iam;
        Aws::IAM::Model::UpdateAccessKeyRequest request;
        request.SetUserName(user_name);
        request.SetAccessKeyId(accessKeyId);
        request.SetStatus(status);

        auto outcome = iam.UpdateAccessKey(request);
        if (outcome.IsSuccess()) {
            std::cout << "Successfully updated status of access key " <<
                accessKeyId << " for user " << user_name << std::endl;
        } else {
            std::cout << "Error updated status of access key " << accessKeyId <<
                " for user " << user_name << ": " <<
                outcome.GetError().GetMessage() << std::endl;
        }
    }
    Aws::ShutdownAPI(options);
    return 0;
}
/**
 * Deletes an access key from an IAM user, based on command line input
 */
int main(int argc, char** argv)
{
    if (argc != 3)
    {
        std::cout << "Usage: delete_access_key <user_name> <access_key_id>"
            << std::endl;
        return 1;
    }

    Aws::SDKOptions options;
    Aws::InitAPI(options);
    {
        Aws::String user_name(argv[1]);
        Aws::String key_id(argv[2]);

        Aws::IAM::IAMClient iam;

        Aws::IAM::Model::DeleteAccessKeyRequest request;
        request.SetUserName(user_name);
        request.SetAccessKeyId(key_id);

        auto outcome = iam.DeleteAccessKey(request);

        if (!outcome.IsSuccess())
        {
            std::cout << "Error deleting access key " << key_id << " from user "
                << user_name << ": " << outcome.GetError().GetMessage() <<
                std::endl;
        }
        else
        {
            std::cout << "Successfully deleted access key " << key_id
                << " for IAM user " << user_name << std::endl;
        }
    }
    Aws::ShutdownAPI(options);
    return 0;
}
Beispiel #16
0
void CDBServConn::_HandleValidateResponse(CImPduValidateResponse* pPdu)
{
    string user_name(pPdu->GetUserName(), pPdu->GetUserNameLen());
	uint32_t result = pPdu->GetResult();
    CDbAttachData attach_data(pPdu->GetAttachData(), pPdu->GetAttachLen());
	log("HandleValidateResp, user_name=%s, result=%d\n", user_name.c_str(), result);

    CImUser* pImUser = CImUserManager::GetInstance()->GetImUserByName(user_name);
	CMsgConn* pMsgConn = NULL;
	if (!pImUser) {
		// can not find the client connection,
		// maybe the client is closed before the DB response arrived
		// do nothing
		log("ImUser for user_name=%s not exist\n", user_name.c_str());
		return;
	} else {
        pMsgConn = pImUser->GetUnValidateMsgConn(attach_data.GetHandle());
		if (!pMsgConn || pMsgConn->IsOpen()) {
			log("no such connection or is validated, user_name=%s\n", user_name.c_str());
			return;
		}
	}

	if (result != 0) {
		result = REFUSE_REASON_DB_VALIDATE_FAILED;
	}
    
	// validate OK, set client validate past, and send FriendListRequest to db storage server
	// else close the client connection
	if (result == 0) {
        user_info_t* user = pPdu->GetUserInfo();
        pImUser->SetUser(user);
        pImUser->SetValidated();
        
        uint32_t user_id = user->user_id;
        CImUserManager::GetInstance()->AddImUserById(user_id, pImUser);
        pImUser->KickOutSameClientType(pMsgConn->GetClientType(), pMsgConn);
        
        CRouteServConn* pRouteConn = get_route_serv_conn();
        if (pRouteConn) {
            CImPduServerKickUser kickPdu(user_id, pMsgConn->GetClientType(), KICK_REASON_DUPLICATE_USER);
            pRouteConn->SendPdu(&kickPdu);
        }
        
        string token = create_uuid();
        log("user_name: %s, uid: %d, token:%s\n", user_name.c_str(), user->user_id, token.c_str());
        pMsgConn->SetToken(token);
        pMsgConn->SetOpen();
        pMsgConn->SendUserActionLog(USER_ACTION_TYPE_LOGIN);
        pMsgConn->SendUserStatusUpdate(USER_STATUS_ONLINE);
        pImUser->ValidateMsgConn(token, pMsgConn);

        CImPduLoginResponse pduLR(result, pImUser->GetIMOnlineStatus(), user, (char*)token.c_str());
        pduLR.SetReserved(pPdu->GetReserved());
        pMsgConn->SendPdu(&pduLR);
	} else {
        CImPduLoginResponse pduLR(result);
        pduLR.SetReserved(pPdu->GetReserved());
        pMsgConn->SendPdu(&pduLR);
        //pMsgConn->Close();
	}
}
Beispiel #17
0
/*
 * Simple "main" function for multiple platforms.
 *
 * Note the special "--" option which terminates the processing of
 * standard options.  All non-standard options (if any) are passed
 * directly to the "init_xxx()" function.
 */
int main(int argc, char *argv[])
{
	int i;

	bool done = FALSE;

	bool new_game = FALSE;

	int show_score = 0;

	cptr mstr = NULL;

	bool args = TRUE;


	/* Save the "program name" XXX XXX XXX */
	argv0 = argv[0];

#ifdef USE_286
	/* Attempt to use XMS (or EMS) memory for swap space */
	if (_OvrInitExt(0L, 0L))
	{
		_OvrInitEms(0, 0, 64);
	}
#endif


#ifdef SET_UID

	/* Default permissions on files */
	(void)umask(022);

# ifdef SECURE
	/* Authenticate */
	Authenticate();
# endif

#endif


	/* Get the file paths */
	init_stuff();


#ifdef SET_UID

	/* Get the user id (?) */
	player_uid = getuid();

#ifdef VMS
	/* Mega-Hack -- Factor group id */
	player_uid += (getgid() * 1000);
#endif

# ifdef SAFE_SETUID

#  ifdef _POSIX_SAVED_IDS

	/* Save some info for later */
	player_euid = geteuid();
	player_egid = getegid();

#  endif

#  if 0	/* XXX XXX XXX */

	/* Redundant setting necessary in case root is running the game */
	/* If not root or game not setuid the following two calls do nothing */

	if (setgid(getegid()) != 0)
	{
		quit("setgid(): cannot set permissions correctly!");
	}

	if (setuid(geteuid()) != 0)
	{
		quit("setuid(): cannot set permissions correctly!");
	}

#  endif

# endif

#endif


	/* Drop permissions */
	safe_setuid_drop();


#ifdef SET_UID

	/* Initialize the "time" checker */
	if (check_time_init() || check_time())
	{
		quit("The gates to Angband are closed (bad time).");
	}

	/* Initialize the "load" checker */
	if (check_load_init() || check_load())
	{
		quit("The gates to Angband are closed (bad load).");
	}

	/* Acquire the "user name" as a default player name */
	user_name(player_name, player_uid);

#ifdef PRIVATE_USER_PATH

	/* Create a directory for the users files. */
	create_user_dir();

#endif /* PRIVATE_USER_PATH */

#endif /* SET_UID */


	/* Process the command line arguments */
	for (i = 1; args && (i < argc); i++)
	{
		/* Require proper options */
		if (argv[i][0] != '-') goto usage;

		/* Analyze option */
		switch (argv[i][1])
		{
			case 'N':
			case 'n':
			{
				new_game = TRUE;
				break;
			}

			case 'F':
			case 'f':
			{
				arg_fiddle = TRUE;
				break;
			}

			case 'W':
			case 'w':
			{
				arg_wizard = TRUE;
				break;
			}

			case 'V':
			case 'v':
			{
				arg_sound = TRUE;
				break;
			}

			case 'G':
			case 'g':
			{
				/* HACK - Graphics mode switches on the original tiles */
				arg_graphics = GRAPHICS_ORIGINAL;
				break;
			}

			case 'R':
			case 'r':
			{
				arg_force_roguelike = TRUE;
				break;
			}

			case 'O':
			case 'o':
			{
				arg_force_original = TRUE;
				break;
			}

			case 'S':
			case 's':
			{
				show_score = atoi(&argv[i][2]);
				if (show_score <= 0) show_score = 10;
				break;
			}

			case 'u':
			case 'U':
			{
				if (!argv[i][2]) goto usage;
				strcpy(player_name, &argv[i][2]);
				break;
			}

			case 'm':
			{
				if (!argv[i][2]) goto usage;
				mstr = &argv[i][2];
				break;
			}

			case 'M':
			{
				arg_monochrome = TRUE;
				break;
			}

			case 'd':
			case 'D':
			{
				change_path(&argv[i][2]);
				break;
			}


			case '-':
			{
				argv[i] = argv[0];
				argc = argc - i;
				argv = argv + i;
				args = FALSE;
				break;
			}

			default:
			usage:
			{
				/* Dump usage information */
				puts("Usage: angband [options] [-- subopts]");
				puts("  -n       Start a new character");
				puts("  -f       Request fiddle mode");
				puts("  -w       Request wizard mode");
				puts("  -v       Request sound mode");
				puts("  -g       Request graphics mode");
				puts("  -o       Request original keyset");
				puts("  -r       Request rogue-like keyset");
				puts("  -M       Request monochrome mode");
				puts("  -s<num>  Show <num> high scores");
				puts("  -u<who>  Use your <who> savefile");
				puts("  -m<sys>  Force 'main-<sys>.c' usage");
				puts("  -d<def>  Define a 'lib' dir sub-path");
				puts("");

#ifdef USE_SDL
				puts("  -msdl    To use SDL");
#endif /* USE_SDL */

#ifdef USE_X11
				puts("  -mx11    To use X11");
				puts("  --       Sub options");
				puts("  -- -d    Set display name");
				puts("  -- -o    Request old 8x8 tile graphics");
				puts("  -- -a    Request Adam Bolt 16x16 tile graphics");
				puts("  -- -b    Request Bigtile graphics mode");
				puts("  -- -s    Turn off smoothscaling graphics");
				puts("  -- -n#   Number of terms to use");
				puts("");
#endif /* USE_X11 */

#ifdef USE_GCU
				puts("  -mgcu    To use GCU (GNU Curses)");
#endif /* USE_GCU */

#ifdef USE_CAP
				puts("  -mcap    To use CAP (\"Termcap\" calls)");
#endif /* USE_CAP */

#ifdef USE_DOS
				puts("  -mdos    To use DOS (Graphics)");
#endif /* USE_DOS */

#ifdef USE_IBM
				puts("  -mibm    To use IBM (BIOS text mode)");
#endif /* USE_IBM */

#ifdef USE_SLA
				puts("  -msla    To use SLA (SLANG)");
#endif /* USE_SLA */

#ifdef USE_LSL
				puts("  -mlsl    To use LSL (Linux-SVGALIB)");
#endif /* USE_LSL */

#ifdef USE_AMI
				puts("  -mami    To use AMI (Amiga)");
#endif /* USE_AMI */

#ifdef USE_VME
				puts("  -mvme    To use VME (VAX/ESA)");
#endif /* USE_VME */

				/* Actually abort the process */
				quit(NULL);
			}
		}
	}

	/* Hack -- Forget standard args */
	if (args)
	{
		argc = 1;
		argv[1] = NULL;
	}


	/* Process the player name */
	process_player_name(TRUE);

	/* Create any missing directories */
	create_needed_dirs();

	/* Install "quit" hook */
	quit_aux = quit_hook;



#ifdef USE_XAW
	/* Attempt to use the "main-xaw.c" support */
	if (!done && (!mstr || (streq(mstr, "xaw"))))
	{
		extern errr init_xaw(int, char**);
		if (0 == init_xaw(argc, argv))
		{
			ANGBAND_SYS = "xaw";
			done = TRUE;
		}
	}
#endif

#ifdef USE_SDL
	/* Attempt to use the "main-sdl.c" support */
	if (!done && (!mstr || (streq(mstr, "sdl"))))
	{
		extern errr init_sdl(int, char**);
		if (0 == init_sdl(argc, argv))
		{
			ANGBAND_SYS = "sdl";
			done = TRUE;
		}
	}
#endif

#ifdef USE_X11
	/* Attempt to use the "main-x11.c" support */
	if (!done && (!mstr || (streq(mstr, "x11"))))
	{
		extern errr init_x11(int, char**);
		if (0 == init_x11(argc, argv))
		{
			ANGBAND_SYS = "x11";
			done = TRUE;
		}
	}
#endif

#ifdef USE_GCU
	/* Attempt to use the "main-gcu.c" support */
	if (!done && (!mstr || (streq(mstr, "gcu"))))
	{
		extern errr init_gcu(int, char**);
		if (0 == init_gcu(argc, argv))
		{
			ANGBAND_SYS = "gcu";
			done = TRUE;
		}
	}
#endif

#ifdef USE_CAP
	/* Attempt to use the "main-cap.c" support */
	if (!done && (!mstr || (streq(mstr, "cap"))))
	{
		extern errr init_cap(int, char**);
		if (0 == init_cap(argc, argv))
		{
			ANGBAND_SYS = "cap";
			done = TRUE;
		}
	}
#endif


#ifdef USE_DOS
	/* Attempt to use the "main-dos.c" support */
	if (!done && (!mstr || (streq(mstr, "dos"))))
	{
		extern errr init_dos(void);
		if (0 == init_dos())
		{
			ANGBAND_SYS = "dos";
			done = TRUE;
		}
	}
#endif

#ifdef USE_IBM
	/* Attempt to use the "main-ibm.c" support */
	if (!done && (!mstr || (streq(mstr, "ibm"))))
	{
		extern errr init_ibm(void);
		if (0 == init_ibm())
		{
			ANGBAND_SYS = "ibm";
			done = TRUE;
		}
	}
#endif


#ifdef USE_EMX
	/* Attempt to use the "main-emx.c" support */
	if (!done && (!mstr || (streq(mstr, "emx"))))
	{
		extern errr init_emx(void);
		if (0 == init_emx())
		{
			ANGBAND_SYS = "emx";
			done = TRUE;
		}
	}
#endif


#ifdef USE_SLA
	/* Attempt to use the "main-sla.c" support */
	if (!done && (!mstr || (streq(mstr, "sla"))))
	{
		extern errr init_sla(void);
		if (0 == init_sla())
		{
			ANGBAND_SYS = "sla";
			done = TRUE;
		}
	}
#endif


#ifdef USE_LSL
	/* Attempt to use the "main-lsl.c" support */
	if (!done && (!mstr || (streq(mstr, "lsl"))))
	{
		extern errr init_lsl(void);
		if (0 == init_lsl())
		{
			ANGBAND_SYS = "lsl";
			done = TRUE;
		}
	}
#endif


#ifdef USE_AMI
	/* Attempt to use the "main-ami.c" support */
	if (!done && (!mstr || (streq(mstr, "ami"))))
	{
		extern errr init_ami(void);
		if (0 == init_ami())
		{
			ANGBAND_SYS = "ami";
			done = TRUE;
		}
	}
#endif


#ifdef USE_VME
	/* Attempt to use the "main-vme.c" support */
	if (!done && (!mstr || (streq(mstr, "vme"))))
	{
		extern errr init_vme(void);
		if (0 == init_vme())
		{
			ANGBAND_SYS = "vme";
			done = TRUE;
		}
	}
#endif


	/* Make sure we have a display! */
	if (!done) quit("Unable to prepare any 'display module'!");


	/* Hack -- If requested, display scores and quit */
	if (show_score > 0) display_scores(0, show_score);


	/* Catch nasty signals */
	signals_init();

	/* Initialize */
	init_angband();

	/* Wait for response */
	pause_line(23);

	/* Play the game */
	play_game(new_game);

	/* Quit */
	quit(NULL);

	/* Exit */
	return (0);
}
Beispiel #18
0
void ud__get_username(char *name)
{
  user_name(name);
};
Beispiel #19
0
void top_twenty(integer this_many)
{
  /*{ Enters a players name on the top twenty list		-JWT-	}*/

  string    list[MAX_HIGH_SCORES+2];
  integer   players_line = 0;
  integer   i1,i2,i3,i4;
  int       n1;
  vtype     o1,s1;
  FILE     *f1;
  boolean   flag;
  char      ch;

  if (py.misc.cheated) {
    exit_game();
  }
  clear_screen();

  if (!read_top_scores(&f1, MORIA_TOP, list, MAX_HIGH_SCORES, &n1, s1)) {
    prt(s1,2,1);
    prt("",3,1);
  } else {

    i3   = total_points();
    flag = false;
    
    if (i3 == 0) {
      i1 = n1;
    } else {
      for (i1=1; (i1 <= n1) && !flag ; ) {   /* XXXX check for corruption */
	sscanf(&(list[i1][13]),"%ld",&i4);
	if (i4 < i3) {
	  flag = true;
	} else {
	  i1++;
	}
      }
    }

    if ((i3 > 0) && ((flag) || (n1 == 0) || (n1 < MAX_HIGH_SCORES))) {

      for (i2 = MAX_HIGH_SCORES-1; i2 >= i1 ; i2--) {
	strcpy(list[i2+1], list[i2]);
      }
      
      user_name(o1);
      
      format_top_score(list[i1], o1, i3, PM.diffic, PM.name,
		       PM.lev, PM.race, PM.tclass);
      
      if (n1 < MAX_HIGH_SCORES) {
	n1++;
      }

      max_score    = n1;
      players_line = i1;
      flag         = false;

      write_top_scores(&f1, list, n1);

    } else { 
      /* did not get a high score */
      max_score = 20;
    }      
    
    if (!close_top_scores(&f1)) {
      prt("Error unlocking score file.",2,1);
      prt("",3,1);
    }
    
    put_buffer("Username     Points  Diff    Character name    Level  Race         Class",1,1);
    put_buffer("____________ ________ _ ________________________ __ __________ ________________",2,1);
    
    i2 = 3;
    if (max_score > n1) {
      max_score = n1;
    }
    
    if (this_many > 0) {
      if (this_many > MAX_HIGH_SCORES) {
	max_score = MAX_HIGH_SCORES;
      } else {
	max_score = this_many;
      }
    }
    for (i1 = 1; i1 <= max_score; i1++) {
      /*insert_str(list[i1],chr(7),''); XXXX  why? */
      if (i1 == players_line) {
	put_buffer_attr(list[i1],i2,1, A_REVERSE);
      } else {
	put_buffer(list[i1],i2,1);
      }
      if ((i1 != 1) && ((i1 % 20) == 0) && (i1 != max_score)) {
	prt("[Press any key to continue, or <Control>-Z to exit]",
	    24,1);
	ch = inkey();
	switch (ch) {
	case 3: case 25: case 26:
	  erase_line(24,1);
	  put_buffer(" ",23,13);
	  exit_game();
	  break;
	}
	clear_rc(3,1);
	i2 = 2;
      }
      i2++;
    } /* end for */
    
    erase_line(23,1);
    put_qio();
    
  } /* end if read_top_scores */
};
Beispiel #20
0
int do_print(const char *path_p, const struct stat *st, int walk_flags, void *unused)
{
	const char *default_prefix = NULL;
	acl_t acl = NULL, default_acl = NULL;
	int error = 0;

	if (walk_flags & WALK_TREE_FAILED) {
		fprintf(stderr, "%s: %s: %s\n", progname, xquote(path_p, "\n\r"),
			strerror(errno));
		return 1;
	}

	/*
	 * Symlinks can never have ACLs, so when doing a physical walk, we
	 * skip symlinks altogether, and when doing a half-logical walk, we
	 * skip all non-toplevel symlinks. 
	 */
	if ((walk_flags & WALK_TREE_SYMLINK) &&
	    ((walk_flags & WALK_TREE_PHYSICAL) ||
	     !(walk_flags & (WALK_TREE_TOPLEVEL | WALK_TREE_LOGICAL))))
		return 0;

	if (opt_print_acl) {
		acl = acl_get_file(path_p, ACL_TYPE_ACCESS);
		if (acl == NULL && (errno == ENOSYS || errno == ENOTSUP))
			acl = acl_get_file_mode(path_p);
		if (acl == NULL)
			goto fail;
	}

	if (opt_print_default_acl && S_ISDIR(st->st_mode)) {
		default_acl = acl_get_file(path_p, ACL_TYPE_DEFAULT);
		if (default_acl == NULL) {
			if (errno != ENOSYS && errno != ENOTSUP)
				goto fail;
		} else if (acl_entries(default_acl) == 0) {
			acl_free(default_acl);
			default_acl = NULL;
		}
	}

	if (opt_skip_base &&
	    (!acl || acl_equiv_mode(acl, NULL) == 0) && !default_acl)
		return 0;

	if (opt_print_acl && opt_print_default_acl)
		default_prefix = "default:";

	if (opt_strip_leading_slash) {
		if (*path_p == '/') {
			if (!absolute_warning) {
				fprintf(stderr, _("%s: Removing leading "
					"'/' from absolute path names\n"),
				        progname);
				absolute_warning = 1;
			}
			while (*path_p == '/')
				path_p++;
		} else if (*path_p == '.' && *(path_p+1) == '/')
			while (*++path_p == '/')
				/* nothing */ ;
		if (*path_p == '\0')
			path_p = ".";
	}

	if (opt_tabular)  {
		if (do_show(stdout, path_p, st, acl, default_acl) != 0)
			goto fail;
	} else {
		if (opt_comments) {
			printf("# file: %s\n", xquote(path_p, "\n\r"));
			printf("# owner: %s\n",
			       xquote(user_name(st->st_uid, opt_numeric), " \t\n\r"));
			printf("# group: %s\n",
			       xquote(group_name(st->st_gid, opt_numeric), " \t\n\r"));
			if ((st->st_mode & (S_ISVTX | S_ISUID | S_ISGID)) && !posixly_correct)
				printf("# flags: %s\n", flagstr(st->st_mode));
		}
		if (acl != NULL) {
			char *acl_text = acl_to_any_text(acl, NULL, '\n',
							 print_options);
			if (!acl_text)
				goto fail;
			if (puts(acl_text) < 0) {
				acl_free(acl_text);
				goto fail;
			}
			acl_free(acl_text);
		}
		if (default_acl != NULL) {
			char *acl_text = acl_to_any_text(default_acl, 
							 default_prefix, '\n',
							 print_options);
			if (!acl_text)
				goto fail;
			if (puts(acl_text) < 0) {
				acl_free(acl_text);
				goto fail;
			}
			acl_free(acl_text);
		}
	}
	if (acl || default_acl || opt_comments)
		printf("\n");

cleanup:
	if (acl)
		acl_free(acl);
	if (default_acl)
		acl_free(default_acl);
	return error;

fail:
	fprintf(stderr, "%s: %s: %s\n", progname, xquote(path_p, "\n\r"),
		strerror(errno));
	error = -1;
	goto cleanup;
}
Beispiel #21
0
QString UserDialog::name() {
  QString s = edname->text().stripWhiteSpace();
  
  return (s.isEmpty()) ? user_name(id()) : s;
}
Beispiel #22
0
int
main( int argc, char * argv[] )
{
    unsigned long ul;
    hudo_t hudo;

    fputs( "[+] Hudo versus Linux/Intel Sudo\n", stderr );
    fputs( "[+] \"Another object superstitiously believed to embody 
magical "
        "powers\"\n", stderr );
    fputs( "[+] Copyright (C) 2001 MaXX\n", stderr );
    fputs( "\n", stderr );

    if ( argc != 4 ) {
        usage( argv[0] == NULL ? "hudo" : argv[0] );
        return( -1 );
    }

    ul = strtoul( argv[1], NULL, 0 );
    if ( ul >= sizeof(architectures) / sizeof(architecture_t) ) {
        usage( argv[0] );
        return( -1 );
    }
    hudo.p_architecture = &( architectures[ul] );

    ul = strtoul( argv[2], NULL, 0 );
    if ( ul % MALLOC_ALIGNMENT || ul < MINSIZE ) {
        usage( argv[0] );
        return( -1 );
    }
    hudo.cmnd_args_size = ul;

    ul = strtoul( argv[3], NULL, 0 );
    if ( ul % MALLOC_ALIGNMENT || ul < MINSIZE ) {
        usage( argv[0] );
        return( -1 );
    }
    hudo.sudo_prompt_size = ul;

    if ( user_name(&hudo) ) {
        return( -1 );
    }
    if ( escape_specifier_and_escaped_size(&hudo) ) {
        return( -1 );
    }

    if ( sudo_argv(&hudo) ) {
        return( -1 );
    }
    if ( sudo_envp(&hudo) ) {
        return( -1 );
    }

    if ( sure_kill(&hudo) ) {
        return( -1 );
    }

    fputs( "[+] Executing sudo..\n", stderr );
    execve( hudo.sudo_argv[0], hudo.sudo_argv, hudo.sudo_envp );
    perror( "[-] execve()" );
    return( -1 );
}
Int32 main (Int32 argc, char *argv[])
{
  dovers(argc, argv);

  // check this before file_init_attach overwrites the user env
  NABoolean sync_with_stdio = (getenv("NO_SYNC_WITH_STDIO") == NULL);

  try
  {
    file_init_attach(&argc, &argv, TRUE, (char *)"");
    msg_debug_hook("sqlci", "sqlci.hook");
    file_mon_process_startup2(true, false);
    atexit(my_mpi_fclose);
  }
  catch (...)
  {
    cerr << "Error while initializing messaging system. Please make sure Trafodion is started and up. Exiting..." << endl;
    exit(1);
  }

  if (sync_with_stdio)
    ios::sync_with_stdio();


  // Establish app user id from the current NT process user identity.
  // This must be done explicitly until the "shadow-process" mechanism
  // is fully implemented.  (It is done too late in cli/Context.cpp.)
  // FX: I'm not sure whether the following code applies
  // 	 to NT only.

 
  // process command line options
  char * in_filename = NULL;
  char * input_string = NULL;
  char * out_filename = NULL;
  char * sock_port = NULL;
  NAString user_name("");
  Int32 i = 1;
  for (; i < argc; i++)
    processOption(argc, argv, 
                           i, 
                          (const char *&)in_filename, 
                          (const char *&)input_string,
                          (const char *&)out_filename,
                          (char *&)sock_port,
                          user_name
      );

  if (sock_port) 
  {
  }  

  // create a SQLCI object
  SqlciEnv * sqlci = new SqlciEnv();
  global_sqlci_env = sqlci;

  if (user_name.length() > 0)
    sqlci->setUserNameFromCommandLine(user_name);


  if (setjmp(ExportJmpBuf))
  {

    printf("\nSQLCI terminating due to assertion failure");
    delete sqlci;
    exit(1); // NAExit(1);
  } 

  ExportJmpBufPtr = &ExportJmpBuf;

  if ((!in_filename) &&
      (out_filename))
    {
      sqlci->setNoBanner(TRUE);

      // create a logfile with the name out_filename.
      // Do not do that if an in_filename is specified. Users should
      // put the log command in the input file.
      char * logf = new char[strlen("LOG ") + 
			    strlen(out_filename) + 
			    strlen(" clear;") +
			    1];
      sprintf(logf, "LOG %s clear;", out_filename);
      sqlci->run(NULL, logf);
      delete logf;

      sqlci->get_logfile()->setNoDisplay(TRUE);
    }

  // setup log4cxx, need to be done here so initLog4cxx can have access to
  // process information since it is needed to compose the log name
  QRLogger::initLog4cxx(QRLogger::QRL_MXEXE);

  // run it -- this is where the action is!
  if (in_filename || input_string)
    sqlci->run(in_filename, input_string);
  else
    sqlci->run();
    
  if ((!in_filename) &&
      (out_filename))
    {
      sqlci->run(NULL, (char *)"LOG;");
    }

  // Now we are done, delete SQLCI object
  delete sqlci;
#ifdef _DEBUG_RTS
  removeProcess();
#endif
#ifdef _DEBUG
  // Delete all contexts
  GetCliGlobals()->deleteContexts();
#endif  // _DEBUG
  return 0;
}
Beispiel #24
0
/*
 * Simple "main" function for multiple platforms.
 *
 * Note the special "--" option which terminates the processing of
 * standard options.  All non-standard options (if any) are passed
 * directly to the "init_xxx()" function.
 */
int main(int argc, char *argv[])
{
	int i;

	bool done = FALSE;

	const char *mstr = NULL;
	const char *soundstr = NULL;

	bool args = TRUE;


	/* Save the "program name" XXX XXX XXX */
	argv0 = argv[0];


#ifdef SET_UID

	/* Default permissions on files */
	(void)umask(022);

#endif /* SET_UID */


#ifdef SET_UID

	/* Get the user id */
	player_uid = getuid();

	/* Save the effective GID for later recall */
	player_egid = getegid();

#endif /* SET_UID */


	/* Drop permissions */
	safe_setuid_drop();


	/* Process the command line arguments */
	for (i = 1; args && (i < argc); i++)
	{
		const char *arg = argv[i];

		/* Require proper options */
		if (*arg++ != '-') goto usage;

		/* Analyze option */
		switch (*arg++)
		{
			case 'n':
				new_game = TRUE;
				break;

			case 'w':
				arg_wizard = TRUE;
				break;

			case 'r':
				arg_rebalance = TRUE;
				break;

			case 'g':
				/* Default graphics tile */
				/* in graphics.txt, 2 corresponds to adam bolt's tiles */
				arg_graphics = 2; 
				if (*arg) arg_graphics = atoi(arg);
				break;

			case 'u':
				if (!*arg) goto usage;

				/* Get the savefile name */
				my_strcpy(op_ptr->full_name, arg, sizeof(op_ptr->full_name));
				continue;

			case 'm':
				if (!*arg) goto usage;
				mstr = arg;
				continue;

			case 's':
				if (!*arg) goto usage;
				soundstr = arg;
				continue;

			case 'd':
				change_path(arg);
				continue;

			case 'x':
				debug_opt(arg);
				continue;

			case '-':
				argv[i] = argv[0];
				argc = argc - i;
				argv = argv + i;
				args = FALSE;
				break;

			default:
			usage:
				puts("Usage: angband [options] [-- subopts]");
				puts("  -n             Start a new character (WARNING: overwrites default savefile without -u)");
				puts("  -w             Resurrect dead character (marks savefile)");
				puts("  -r             Rebalance monsters");
				puts("  -g             Request graphics mode");
				puts("  -x<opt>        Debug options; see -xhelp");
				puts("  -u<who>        Use your <who> savefile");
				puts("  -d<path>       Store pref files and screendumps in <path>");
				puts("  -s<mod>        Use sound module <sys>:");
				for (i = 0; i < (int)N_ELEMENTS(sound_modules); i++)
					printf("     %s   %s\n", sound_modules[i].name,
					       sound_modules[i].help);
				puts("  -m<sys>        Use module <sys>, where <sys> can be:");

				/* Print the name and help for each available module */
				for (i = 0; i < (int)N_ELEMENTS(modules); i++)
					printf("     %s   %s\n",
					       modules[i].name, modules[i].help);

				/* Actually abort the process */
				quit(NULL);
		}
		if (*arg) goto usage;
	}

	/* Hack -- Forget standard args */
	if (args)
	{
		argc = 1;
		argv[1] = NULL;
	}

	/* Install "quit" hook */
	quit_aux = quit_hook;

	/* If we were told which mode to use, then use it */
	if (mstr)
		ANGBAND_SYS = mstr;

	if (setlocale(LC_CTYPE, "")) {
		/* Require UTF-8 */
		if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0)
			quit("Angband requires UTF-8 support");
	}

	/* Get the file paths */
	init_stuff();

	/* Try the modules in the order specified by modules[] */
	for (i = 0; i < (int)N_ELEMENTS(modules); i++)
	{
		/* User requested a specific module? */
		if (!mstr || (streq(mstr, modules[i].name)))
		{
			ANGBAND_SYS = modules[i].name;
			if (0 == modules[i].init(argc, argv))
			{
				done = TRUE;
				break;
			}
		}
	}

	/* Make sure we have a display! */
	if (!done) quit("Unable to prepare any 'display module'!");

#ifdef SET_UID

	/* Get the "user name" as a default player name, unless set with -u switch */
	if (!op_ptr->full_name[0])
	{
		user_name(op_ptr->full_name, sizeof(op_ptr->full_name), player_uid);
	}

	/* Create any missing directories */
	create_needed_dirs();

#endif /* SET_UID */

	/* Process the player name */
	process_player_name(TRUE);

	/* Try the modules in the order specified by sound_modules[] */
	for (i = 0; i < (int)N_ELEMENTS(sound_modules); i++)
		if (!soundstr || streq(soundstr, sound_modules[i].name))
			if (0 == sound_modules[i].init(argc, argv))
				break;

	/* Catch nasty signals */
	signals_init();

	/* Set up the command hook */
	cmd_get_hook = default_get_cmd;

	/* Set up the display handlers and things. */
	init_display();

	/* Play the game */
	play_game();

	/* Free resources */
	cleanup_angband();

	/* Quit */
	quit(NULL);

	/* Exit */
	return (0);
}
Beispiel #25
0
/*<
The first thing to do is write a handler function which takes a request and a
response and does all request-specific work. Later, we will look at writing
the code that calls this function.
>*/
int handle_request(cgi::request& req, cgi::response& resp)
{
/*<
In our request handler, we will assume that the request has been fully-parsed
and we can access all of the request data. The request data is available using
public members of a `cgi::request`. These member variables are instances of
the [classref boost::cgi::common::data_map_proxy data_map_proxy], which has a
`std::map<>`-like interface along with some additional helper functions to
facilitate common CGI tasks, such as lexical conversion to different types.
[footnote The data is stored internally in a single `fusion::vector<>` which
is not currently publicly accessible.]

A CGI request has several types of variables available. These are listed in
the table below, assuming that `req` is an instance of `cgi::request`:

[table
  [[Source] [Variable] [Description]]
  [
    [Environment] [`req.env`] [The environment of a CGI request contains most
    of the information you will need to handle a request. There is a basic set of
    common environment variables that you can expect to be set by most HTTP
    servers around. A list of them is available on the __TODO__ (link) variables
    page.]
  ]
  [
    [GET] [`req.get`] [The variables passed in the query string of an HTTP GET
    request.]
  ]
  [
    [POST] [`req.post`] [The HTTP POST data that is sent in an HTTP request's
    body. For file uploads, the file's name is the value stored in the map. You
    should use `req.uploads` for more information on file uploads.]
  ]
  [
    [Cookies] [`req.cookies`] [Cookies are sent in the HTTP_COOKIE environment
    variable. These can store limited amounts session information on the client's
    machine, such as database session ids or tracking information.]
  ]
  [
    [File Uploads] [`req.uploads`] [File uploads, sent in an HTTP POST where
    the body is MIME-encoded as multipart/form-data. Uploaded files are written
    onto the server's file system and meta-data related to the file is stored in
    a [classref boost::cgi::common::form_part form_part]. The value of an upload
    variable is the `form_part` for the upload and all `form_part`s are implicitly
    convertible to a string, which corresponds to the original filename.]
  ]
  [
    [Form] [`req.form`] [The form variables are either the GET variables or
    the POST variables, depending on the request method of the request.]
  ]
]

Let's assume you now want to check if the user has a cookie, "user_name",
set. We can check if a user has a cookie set like this:
>*/
  if (req.cookies.count("user_name"))
  {
/*<
First, we need to be able to clear the cookie we are setting. We will reset
the cookie if the user navigates to `"/path/to/script?reset=1"`.

The `reset` variable in the query string is a GET variable. The request data
is accessed through a proxy class which works just like a `std::map<>` with
some extra features.

One of them is `pick`, which looks up a key in the map and returns the value
if it is found. Otherwise it returns a default value, which is the second
argument. 

The default value can be any type that supports
[@http://boost.org/libs/lexical_cast Boost.Lexical_cast]. If the key isn't
found in the map, or the value cannot be cast to the type of the default
value, the default is returned.
>*/
    if (req.get.pick<std::string>("reset", "") == "1")
    {
      resp<< cgi::cookie("user_name") /*<
Set a cookie with no value to delete it.
>*/
          << cgi::redirect(req, req.script_name()) /*<
The `cgi::redirect` free function returns a `"Location"` header that will
redirect the user to the specified URL. This URL can be a relative or absolute
but an absolute URL is always returned. To perform an internal redirect, use
`cgi::location` instead.
>*/
          << cgi::content_type("text/plain");
    }
    else
    {
      std::string user_name( req.cookies["user_name"] );
/*<
Looking up a request cookie in `req.cookies` really returns a `cgi::cookie`.
The line above works though because a `cgi::cookie` is implicitly convertible
to a `std::string`.

The lookup is case-insensitive, so "USER_NAME" and "User_Name" would be
equivalent lookup keys.

If the cookie is set, we'll be polite and say hello before quitting.
>*/
      if (!user_name.empty())
      {
        resp<< cgi::content_type("text/html")
            << "<p>Hello there, " << req.cookies["user_name"]
            << ". How are you?</p>"
            << "<a href=\"" << req.script_name() << "?reset=1\">Reset</a>";
      }
    }
/*<
That's all we want to say for now, so we can return.

If you are familiar with CGI programming, you will notice the lack of any
HTTP headers in the response. A `cgi::response` handles headers separately
to the body. You can set headers at any point and when you send the response
the headers will all be sent first.

If you don't explicitly set any response headers, a default header
`"Content-type: text/plain"` is sent, followed by the usual HTTP end-of-line
`"\r\n"` and a blank line which indicates the end of the headers and the
start of response body.
>*/
  } else
/*<
If the cookie isn't set, we will check if the user has posted a __GET__/
__POST__ form with their name.
>*/
  if (req.form.count("user_name"))
  {
    std::string user_name (req.form["user_name"]);
/*<
If they have told us their name, we should set a cookie so we remember it next
time. Then we can say hello and exit.

There are two ways to set a cookie: either directly using
`req.set_cookie("user_name", user_name)` or the method shown. You can also
send an expiry date and a path for the cookie.[footnote 
See [@http://tools.ietf.org/html/rfc822 RFC822] for more.
]
Note that if you set a cookie with no value, the cookie will be deleted.

Again, the request object isn't buffered, so we are going to keep using the
`response` in case something breaks and we end up not wanting to set the
cookie. The cookie we set below will expire when the client closes their
browser.

This time, we shall send a Date header. If we do this (ie. send a header
ourselves), we must also set the Content-type header, like below.
>*/
    resp<< cgi::cookie("user_name", user_name)
        << cgi::header("Date", "Tue, 15 Nov 1994 08:12:31 GMT")
        << cgi::content_type("text/html")
        << "Hello there, " << user_name << ". You're new around here."
        << "user_name.length() = " << user_name.length() ;
  }
  else
  {
/*<
Now, if we have no idea who they are, we'll send a form asking them for their
name. As the default `"Content-type"` header is `"text/plain"`, we'll change
this to `"text/html"` so the user's browser will display the HTML form. You
can do this using
    `set_header(req,  "Content-type", "text/html")`
or
    `resp<< header("Content-type", "text/html")`.
Since writing with raw strings is error-prone, the shortcut below is available.
>*/
  resp<< cgi::content_type("text/html")
      << "Hello there. What's your name?" "<p />"
         "<form method='POST'>"
         "<input type='text' name='user_name' />"
         "<input type='submit' />";
  }
/*<
A CGI program will handle one request each time it is invoked. Returning a
non-zero status to the OS indicates an error handling the request. I don't
know that HTTP servers treat non-zero exit codes specially.[footnote I may well
may well be wrong about this.]

To send the response back to the request, use `cgi::commit`. The third
`status` argument is optional and defaults to zero. The return value of
`cgi::commit` is `status`.
>*/
  return cgi::commit(req, resp);
}
Beispiel #26
0
UserDialog::UserDialog(const QPoint & p)
    : QDialog(0)
{
    setWindowTitle("Choose user");
    setModal(true);
    move(p);

    QVBoxLayout * vbox = new QVBoxLayout(this);
    QHBoxLayout * hbox;
    QLabel * lbl1;
    QLabel * lbl2;

    vbox->setMargin(5);

    QLabel * lbl =
        new QLabel("\nSelect a user to get its identity,\nyou may change or set his name\n",
                   this);

    lbl->setAlignment(::Qt::AlignCenter);
    vbox->addWidget(lbl);

    hbox = new QHBoxLayout();
    vbox->addLayout(hbox);
    hbox->setMargin(5);
    lbl1 = new QLabel("User : "******" (" + s + ")");
    }

    ids->setCurrentIndex(user_id() - 2);

    QSizePolicy sp = ids->sizePolicy();

    sp.setHorizontalPolicy(QSizePolicy::Expanding);
    ids->setSizePolicy(sp);

    hbox->addWidget(ids);

    hbox = new QHBoxLayout();
    vbox->addLayout(hbox);
    hbox->setMargin(5);
    lbl2 = new QLabel("New name : ", this);
    lbl1->setFixedWidth(lbl2->sizeHint().width());
    hbox->addWidget(lbl2);
    edname = new QLineEdit(this);
    hbox->addWidget(edname);

    hbox = new QHBoxLayout();
    vbox->addLayout(hbox);
    hbox->setMargin(5);

    QPushButton * ok = new QPushButton("Ok", this);
    QPushButton * cancel = new QPushButton("Cancel", this);

    hbox->addWidget(new QLabel(this));
    hbox->addWidget(ok);
    hbox->addWidget(new QLabel(this));
    hbox->addWidget(cancel);
    hbox->addWidget(new QLabel(this));

    connect(ok, SIGNAL(clicked()), this, SLOT(accept()));
    connect(cancel, SIGNAL(clicked()), this, SLOT(reject()));
}
Beispiel #27
0
QString UserDialog::name()
{
    QString s = edname->text().trimmed();

    return (s.isEmpty()) ? user_name(id()) : s;
}
Beispiel #28
0
/**
 * Simple "main" function for multiple platforms.
 *
 * Note the special "--" option which terminates the processing of
 * standard options.  All non-standard options (if any) are passed
 * directly to the "init_xxx()" function.
 */
int main(int argc, char *argv[])
{
	int i;

	bool done = FALSE;

	const char *mstr = NULL;
	const char *soundstr = NULL;

	bool args = TRUE;

	/* Save the "program name" XXX XXX XXX */
	argv0 = argv[0];

#ifdef UNIX

	/* Default permissions on files */
	(void)umask(022);

	/* Get the user id */
	player_uid = getuid();

#endif /* UNIX */

#ifdef SETGID

	/* Save the effective GID for later recall */
	player_egid = getegid();

#endif /* UNIX */


	/* Drop permissions */
	safe_setuid_drop();

	/* Get the file paths 
	 * Paths may be overriden by -d options, so this has to occur *before* 
	 * processing command line args */
	init_stuff();

	/* Process the command line arguments */
	for (i = 1; args && (i < argc); i++) {
		const char *arg = argv[i];

		/* Require proper options */
		if (*arg++ != '-') goto usage;

		/* Analyze option */
		switch (*arg++)
		{
			case 'l':
				list_saves();
				exit(0);

			case 'n':
				new_game = TRUE;
				break;

			case 'w':
				arg_wizard = TRUE;
				break;

			case 'p':
				arg_power = TRUE;
				break;

			case 'r':
				arg_rebalance = TRUE;
				break;

			case 'g':
				/* Default graphics tile */
				/* in graphics.txt, 2 corresponds to adam bolt's tiles */
				arg_graphics = 2; 
				if (*arg) arg_graphics = atoi(arg);
				break;

			case 'u': {

				if (!*arg) goto usage;
				my_strcpy(op_ptr->full_name, arg, sizeof op_ptr->full_name);

				/* The difference here is because on setgid we have to be
				 * careful to only let the player have savefiles stored in
				 * the central save directory.  Sanitising input using
				 * player_safe_name() removes anything like that.
				 *
				 * But if the player is running with per-user saves, they
				 * can do whatever the hell they want.
				 */
#ifdef SETGID
				savefile_set_name(player_safe_name(player, FALSE));
#else
				savefile_set_name(arg);
#endif /* SETGID */

				continue;
			}

			case 'm':
				if (!*arg) goto usage;
				mstr = arg;
				continue;

			case 's':
				if (!*arg) goto usage;
				soundstr = arg;
				continue;

			case 'd':
				change_path(arg);
				continue;

			case 'x':
				debug_opt(arg);
				continue;

			case '-':
				argv[i] = argv[0];
				argc = argc - i;
				argv = argv + i;
				args = FALSE;
				break;

			default:
			usage:
				puts("Usage: angband [options] [-- subopts]");
				puts("  -n             Start a new character (WARNING: overwrites default savefile without -u)");
				puts("  -l             Lists all savefiles you can play");
				puts("  -w             Resurrect dead character (marks savefile)");
				puts("  -r             Rebalance monsters");
				puts("  -g             Request graphics mode");
				puts("  -x<opt>        Debug options; see -xhelp");
				puts("  -u<who>        Use your <who> savefile");
				puts("  -d<dir>=<path> Override a specific directory with <path>. <path> can be:");
				for (i = 0; i < (int)N_ELEMENTS(change_path_values); i++) {
#ifdef SETGID
					if (!change_path_values[i].setgid_ok) continue;
#endif
					printf("    %s (default is %s)\n", change_path_values[i].name, *change_path_values[i].path);
				}
				puts("                 Multiple -d options are allowed.");
				puts("  -s<mod>        Use sound module <sys>:");
				for (i = 0; i < (int)N_ELEMENTS(sound_modules); i++)
					printf("     %s   %s\n", sound_modules[i].name,
					       sound_modules[i].help);
				puts("  -m<sys>        Use module <sys>, where <sys> can be:");

				/* Print the name and help for each available module */
				for (i = 0; i < (int)N_ELEMENTS(modules); i++)
					printf("     %s   %s\n",
					       modules[i].name, modules[i].help);

				/* Actually abort the process */
				quit(NULL);
		}
		if (*arg) goto usage;
	}

	/* Hack -- Forget standard args */
	if (args) {
		argc = 1;
		argv[1] = NULL;
	}

	/* Install "quit" hook */
	quit_aux = quit_hook;

	/* If we were told which mode to use, then use it */
	if (mstr)
		ANGBAND_SYS = mstr;

	if (setlocale(LC_CTYPE, "")) {
		/* Require UTF-8 */
		if (strcmp(nl_langinfo(CODESET), "UTF-8") != 0)
			quit("Angband requires UTF-8 support");
	}

	/* Try the modules in the order specified by modules[] */
	for (i = 0; i < (int)N_ELEMENTS(modules); i++) {
		/* User requested a specific module? */
		if (!mstr || (streq(mstr, modules[i].name))) {
			ANGBAND_SYS = modules[i].name;
			if (0 == modules[i].init(argc, argv)) {
				done = TRUE;
				break;
			}
		}
	}

	/* Make sure we have a display! */
	if (!done) quit("Unable to prepare any 'display module'!");

#ifdef UNIX

	/* Get the "user name" as default player name, unless set with -u switch */
	if (!op_ptr->full_name[0]) {
		user_name(op_ptr->full_name, sizeof(op_ptr->full_name), player_uid);

		/* Set the savefile to load */
		savefile_set_name(player_safe_name(player, FALSE));
	}

	/* Create any missing directories */
	create_needed_dirs();

#endif /* UNIX */

	/* Try the modules in the order specified by sound_modules[] */
	for (i = 0; i < (int)N_ELEMENTS(sound_modules); i++)
		if (!soundstr || streq(soundstr, sound_modules[i].name))
			if (0 == sound_modules[i].init(argc, argv))
				break;

	/* Catch nasty signals */
	signals_init();

	/* Set up the command hook */
	cmd_get_hook = textui_get_cmd;

	/* Set up the display handlers and things. */
	init_display();
	init_angband();
	textui_init();

	/* Wait for response */
	pause_line(Term);

	/* Play the game */
	play_game(new_game);

	/* Free resources */
	textui_cleanup();
	cleanup_angband();

	/* Quit */
	quit(NULL);

	/* Exit */
	return (0);
}
Beispiel #29
0
/*
 * Simple "main" function for multiple platforms.
 *
 * Note the special "--" option which terminates the processing of
 * standard options.  All non-standard options (if any) are passed
 * directly to the "init_xxx()" function.
 */
int main(int argc, char *argv[])
{
	int i;

	bool done = FALSE;

	bool new_game = FALSE;

	int show_score = 0;

	cptr mstr = NULL;

	bool args = TRUE;


	/* Save the "program name" XXX XXX XXX */
	argv0 = argv[0];

#ifdef USE_286
	/* Attempt to use XMS (or EMS) memory for swap space */
	if (_OvrInitExt(0L, 0L))
	{
		_OvrInitEms(0, 0, 64);
	}
#endif


#ifdef SET_UID

	/* Default permissions on files */
	(void)umask(022);

# ifdef SECURE
	/* Authenticate */
	Authenticate();
# endif

#endif


	/* Get the file paths */
	init_stuff();


#ifdef SET_UID

	/* Get the user id (?) */
	player_uid = getuid();

#ifdef VMS
	/* Mega-Hack -- Factor group id */
	player_uid += (getgid() * 1000);
#endif

# ifdef SAFE_SETUID

#  ifdef _POSIX_SAVED_IDS

	/* Save some info for later */
	player_euid = geteuid();
	player_egid = getegid();

#  endif

#  if 0	/* XXX XXX XXX */

	/* Redundant setting necessary in case root is running the game */
	/* If not root or game not setuid the following two calls do nothing */

	if (setgid(getegid()) != 0)
	{
		quit("setgid(): cannot set permissions correctly!");
	}

	if (setuid(geteuid()) != 0)
	{
		quit("setuid(): cannot set permissions correctly!");
	}

#  endif

# endif

#endif


#ifdef SET_UID

	/* Initialize the "time" checker */
	if (check_time_init() || check_time())
	{
		quit("The gates to Angband are closed (bad time).");
	}

	/* Initialize the "load" checker */
	if (check_load_init() || check_load())
	{
		quit("The gates to Angband are closed (bad load).");
	}

	/* Acquire the "user name" as a default player name */
#ifdef ANGBAND_2_8_1
	user_name(player_name, player_uid);
#else /* ANGBAND_2_8_1 */
	user_name(op_ptr->full_name, player_uid);
#endif /* ANGBAND_2_8_1 */

#ifdef PRIVATE_USER_PATH

	/* Create a directory for the users files. */
	create_user_dir();

#endif /* PRIVATE_USER_PATH */

#endif /* SET_UID */


	/* Process the command line arguments */
	for (i = 1; args && (i < argc); i++)
	{
		/* Require proper options */
		if (argv[i][0] != '-') game_usage();

		/* Analyze option */
		switch (argv[i][1])
		{
			case 'N':
			case 'n':
			{
				new_game = TRUE;
				break;
			}

			case 'F':
			case 'f':
			{
				arg_fiddle = TRUE;
				break;
			}

			case 'W':
			case 'w':
			{
				arg_wizard = TRUE;
				break;
			}

			case 'V':
			case 'v':
			{
				arg_sound = TRUE;
				break;
			}

			case 'G':
			case 'g':
			{
				/* HACK - Graphics mode switches on the original tiles */
				arg_graphics = GRAPHICS_ORIGINAL;
				break;
			}

			case 'R':
			case 'r':
			{
				arg_force_roguelike = TRUE;
				break;
			}

			case 'O':
			case 'o':
			{
				arg_force_original = TRUE;
				break;
			}

			case 'S':
			case 's':
			{
				show_score = atoi(&argv[i][2]);
				if (show_score <= 0) show_score = 10;
				break;
			}

			case 'u':
			case 'U':
			{
				if (!argv[i][2]) game_usage();
#ifdef ANGBAND_2_8_1
				strncpy(player_name, &argv[i][2], 32);
				player_name[31] = '\0';
#else /* ANGBAND_2_8_1 */
				strncpy(op_ptr->full_name, &argv[i][2], 32);
				op_ptr->full_name[31] = '\0';
#endif /* ANGBAND_2_8_1 */
				break;
			}

			case 'm':
			{
				if (!argv[i][2]) game_usage();
				mstr = &argv[i][2];
				break;
			}

			case 'M':
			{
				arg_monochrome = TRUE;
				break;
			}

			case 'd':
			case 'D':
			{
				change_path(&argv[i][2]);
				break;
			}

			case '-':
			{
				argv[i] = argv[0];
				argc = argc - i;
				argv = argv + i;
				args = FALSE;
				break;
			}

			default:
			{
				 /* Default usage-help */
				 game_usage();
			}
		}
	}

	/* Hack -- Forget standard args */
	if (args)
	{
		argc = 1;
		argv[1] = NULL;
	}


	/* Process the player name */
	process_player_name(TRUE);



	/* Install "quit" hook */
	quit_aux = quit_hook;


	/* 
	 * Drop privs (so X11 will work correctly)
	 * unless we are running the Linux-SVGALib version.
	 *
	 * (In which case we initialize after safe_setuid_grab()
	 * is called.)
	 */
 
 	safe_setuid_drop();

#ifdef USE_XAW
	/* Attempt to use the "main-xaw.c" support */
	if (!done && (!mstr || (streq(mstr, "xaw"))))
	{
		if (0 == init_xaw(argc, argv))
		{
			ANGBAND_SYS = "xaw";
			done = TRUE;
		}
	}
#endif


#ifdef USE_X11
	/* Attempt to use the "main-x11.c" support */
	if (!done && (!mstr || (streq(mstr, "x11"))))
	{
		if (0 == init_x11(argc, argv))
		{
			ANGBAND_SYS = "x11";
			done = TRUE;
		}
	}
#endif


#ifdef USE_XPJ
	/* Attempt to use the "main-xpj.c" support */
	if (!done && (!mstr || (streq(mstr, "xpj"))))
	{
		if (0 == init_xpj(argc, argv))
		{
			ANGBAND_SYS = "xpj";
			done = TRUE;
		}
	}
#endif


#ifdef USE_GTK
	/* Attempt to use the "main-gtk.c" support */
	if (!done && (!mstr || (streq(mstr, "gtk"))))
	{
		if (0 == init_gtk((unsigned char*) &new_game, argc, argv))
		{
			done = TRUE;
		}
	}
#endif


#ifdef USE_GCU
	/* Attempt to use the "main-gcu.c" support */
	if (!done && (!mstr || (streq(mstr, "gcu"))))
	{
		if (0 == init_gcu())
		{
			ANGBAND_SYS = "gcu";
			done = TRUE;
		}
	}
#endif

#ifdef USE_CAP
	/* Attempt to use the "main-cap.c" support */
	if (!done && (!mstr || (streq(mstr, "cap"))))
	{
		if (0 == init_cap(argc, argv))
		{
			ANGBAND_SYS = "cap";
			done = TRUE;
		}
	}
#endif


#ifdef USE_DOS
	/* Attempt to use the "main-dos.c" support */
	if (!done && (!mstr || (streq(mstr, "dos"))))
	{
		if (0 == init_dos())
		{
			ANGBAND_SYS = "dos";
			done = TRUE;
		}
	}
#endif

#ifdef USE_IBM
	/* Attempt to use the "main-ibm.c" support */
	if (!done && (!mstr || (streq(mstr, "ibm"))))
	{
		if (0 == init_ibm())
		{
			ANGBAND_SYS = "ibm";
			done = TRUE;
		}
	}
#endif


#ifdef USE_EMX
	/* Attempt to use the "main-emx.c" support */
	if (!done && (!mstr || (streq(mstr, "emx"))))
	{
		if (0 == init_emx())
		{
			ANGBAND_SYS = "emx";
			done = TRUE;
		}
	}
#endif


#ifdef USE_SLA
	/* Attempt to use the "main-sla.c" support */
	if (!done && (!mstr || (streq(mstr, "sla"))))
	{
		if (0 == init_sla())
		{
			ANGBAND_SYS = "sla";
			done = TRUE;
		}
	}
#endif


#ifdef USE_AMI
	/* Attempt to use the "main-ami.c" support */
	if (!done && (!mstr || (streq(mstr, "ami"))))
	{
		if (0 == init_ami())
		{
			ANGBAND_SYS = "ami";
			done = TRUE;
		}
	}
#endif


#ifdef USE_VME
	/* Attempt to use the "main-vme.c" support */
	if (!done && (!mstr || (streq(mstr, "vme"))))
	{
		if (0 == init_vme())
		{
			ANGBAND_SYS = "vme";
			done = TRUE;
		}
	}
#endif

#ifdef USE_VCS
	/* Attempt to use the "main-vcs.c" support */
	if (!done && (!mstr || (streq(mstr, "vcs"))))
	{
		if (0 == init_vcs(argc, argv))
		{
			ANGBAND_SYS = "vcs";
			done = TRUE;
		}
	}
#endif /* USE_VCS */

	/* Grab privs (dropped above for X11) */
 	safe_setuid_grab();

#ifdef USE_LSL
	/* Attempt to use the "main-lsl.c" support */
	if (!done && (!mstr || (streq(mstr, "lsl"))))
	{
		if (0 == init_lsl())
		{
			ANGBAND_SYS = "lsl";
			done = TRUE;
		}
	}
#endif




	/* Make sure we have a display! */
	if (!done) quit("Unable to prepare any 'display module'!");


	/* Hack -- If requested, display scores and quit */
	if (show_score > 0) display_scores(0, show_score);

	/* Gtk initializes earlier */
	if (!streq(ANGBAND_SYS, "gtk"))
	{
		/* Catch nasty signals */
		signals_init();

		/* Initialize */
		init_angband();
	}
	
	/* Wait for response */
	pause_line(23);

	/* Play the game */
	play_game(new_game);

	/* Quit */
	quit(NULL);

	/* Exit */
	return (0);
}
Beispiel #30
0
void BrowserNode::menu() {
  QString who = user_name(user_id());
  
  if (who.isEmpty())
    who = "<" + QString::number(user_id()) + ">";
  
  QPopupMenu m(0);
  
  m.insertItem("Package " + text(0), -1);

  if (! ro) {
    m.insertSeparator();
    if (owner == user_id()) {
      m.insertItem("Protect this package ("CTRL"+p)", 3);
      m.insertItem("Unassign this package ("CTRL"+u)", 2);
    }
    else if (owner == -1) {
      m.insertItem("Protect this package ("CTRL"+p)", 3);
      m.insertItem("Assign this package to " + who + " ("CTRL"+a)", 1);
    }
    else if (owner < 2) {
      m.insertItem("Assign this package to " + who + " ("CTRL"+a)", 1);
      m.insertItem("Unassign this package (Ctrl+u)", 2);
    }
    else {
      m.insertItem("Protect this package ("CTRL"+p)", 3);
      m.insertItem("Unassign this package ("CTRL"+u)", 2);
      m.insertItem("Assign this package to " + who + " ("CTRL"+a)", 1);
    }
  }
  
  if (firstChild() != 0) {
    m.insertSeparator();
    m.insertItem("Protect " + who + "'s packages recursively from this one", 10);
    m.insertItem("Protect unassigned packages recursively from this one", 11);
    m.insertItem("Protect all packages recursively from this one (Alt+p)", 12);
    m.insertItem("Assign to " + who + " unassigned packages recursively from this one", 13);
    m.insertItem("Assign to " + who + " all packages recursively from this one (Alt+a)", 14);
    m.insertItem("Unassign " + who + "'s packages recursively from this one", 15);
    m.insertItem("Unassign all packages recursively from this one (Alt+u)", 16);
  }
  else if (ro)
    return;
  
  int choice = m.exec(QCursor::pos());
  
  QApplication::setOverrideCursor(Qt::waitCursor);
  
  switch (choice) {
  case 1:
    assign(user_id());
    break;
  case 2:
    assign(-1);
    break;
  case 3:
    assign(0);
    break;
  case 10:
    assign_mine(0);
    break;
  case 11:
    assign_unassigned(0);
    break;
  case 12:
    assign_all(0);
    break;
  case 13:
    assign_unassigned(user_id());
    break;
  case 14:
    assign_all(user_id());
    break;
  case 15:
    assign_mine(-1);
    break;
  case 16:
    assign_all(-1);
  default:
    break;
  }
  
  QApplication::restoreOverrideCursor();
}