Example #1
0
void get_storage_items (const Uint8 *in_data, int len)
{
	int i;
	int cat, pos;
	int idx;
	int plen;

	if (item_uid_enabled)
		plen=10;
	else
		plen=8;

	if (in_data[0] == 255)
	{
		// It's just an update - make sure we're in the right category
		idx = 2;
		active_storage_item = SDL_SwapLE16(*((Uint16*)(&in_data[idx+6])));
		
		for (i = 0; i < STORAGE_ITEMS_SIZE; i++)
		{
			if ((storage_items[i].pos == SDL_SwapLE16(*((Uint16*)(&in_data[idx+6])))) && (storage_items[i].quantity > 0))
			{
				storage_items[i].image_id = SDL_SwapLE16(*((Uint16*)(&in_data[idx])));
				storage_items[i].quantity = SDL_SwapLE32(*((Uint32*)(&in_data[idx+2])));
				if (item_uid_enabled)
					storage_items[i].id = SDL_SwapLE16(*((Uint16*)(&in_data[idx+8])));
				else
					storage_items[i].id = unset_item_uid;
				return;
			}
		}

		for (i = 0; i < STORAGE_ITEMS_SIZE; i++)
		{
			if (storage_items[i].quantity == 0)
			{
				if (item_uid_enabled)
					storage_items[i].id = SDL_SwapLE16(*((Uint16*)(&in_data[idx+8])));
				else
					storage_items[i].id = unset_item_uid;
				storage_items[i].pos = SDL_SwapLE16(*((Uint16*)(&in_data[idx+6])));
				storage_items[i].image_id = SDL_SwapLE16(*((Uint16*)(&in_data[idx])));
				storage_items[i].quantity = SDL_SwapLE32(*((Uint32*)(&in_data[idx+2])));
				no_storage++;
				return;
			}
		}
	}

	no_storage = (len - 2) / plen;

	cat = find_category(in_data[1]);
	if (cat >= 0)
	{
		storage_categories[cat].name[0] = to_color_char (c_red3);
		if (selected_category != -1 && cat != selected_category)
			storage_categories[selected_category].name[0] = to_color_char (c_orange1);
		set_window_name(" - ", storage_categories[cat].name+1);
		selected_category = cat;
	}

	idx = 2;
	for (i = 0; i < no_storage && i < STORAGE_ITEMS_SIZE; i++, idx += plen)
	{
		storage_items[i].image_id = SDL_SwapLE16(*((Uint16*)(&in_data[idx])));
		storage_items[i].quantity = SDL_SwapLE32(*((Uint32*)(&in_data[idx+2])));
		storage_items[i].pos = SDL_SwapLE16(*((Uint16*)(&in_data[idx+6])));
		if (item_uid_enabled)
			storage_items[i].id = SDL_SwapLE16(*((Uint16*)(&in_data[idx+8])));
		else
			storage_items[i].id = unset_item_uid;
	}
	
	for ( ; i < STORAGE_ITEMS_SIZE; i++)
	{
		storage_items[i].quantity=0;
	}
	
	vscrollbar_set_pos(storage_win, STORAGE_SCROLLBAR_ITEMS, 0);
	pos = vscrollbar_get_pos(storage_win, STORAGE_SCROLLBAR_CATEGORIES);
	if (cat < pos) {
		vscrollbar_set_pos(storage_win, STORAGE_SCROLLBAR_CATEGORIES, cat);
	} else	if (cat >= pos + STORAGE_CATEGORIES_DISPLAY) {
		vscrollbar_set_pos(storage_win, STORAGE_SCROLLBAR_CATEGORIES, cat - STORAGE_CATEGORIES_DISPLAY + 1);
	}

	if (selected_category != -1)
		category_updated();
}
Example #2
0
int init (int argc, char *argv[])
{
    char    *p;
    int     rc = 0, oldmode;
    url_t   u;
    int     x0=-1, y0=-1, r=-1, c=-1;
    struct hostent     *remote;
    char    buffer[MAX_PATH];

    if (action == ACTION_TESTONLY) exit (0);
    if (action == ACTION_BADAGS)
    {
        usage ();
        exit (1);
    }

    if (options.keep_winsize)
    {
        r = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "rows");
        c = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "cols");
        if (r == 0 && c == 0) r = -1, c = -1;
    }

    if (options.keep_winpos)
    {
        x0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "x0");
        y0 = cfg_get_integer (CONFIG_NFTP, fl_opt.platform_nick, "y0");
        if (x0 == 0 || y0 == 0) x0 = -1, y0 = -1;
    }

    p = cfg_get_string (CONFIG_NFTP, fl_opt.platform_nick, "font");
    if (p[0] == '\0') p = NULL;

    fly_init (x0, y0, r, c, p);
    if (options.show_hw_cursor) video_cursor_state (1);
    fly_mouse (options.mouse);
    wintitle = get_window_name ();

    if (fl_opt.platform == PLATFORM_OS2_VIO)
    {
        strcpy (buffer, paths.system_libpath);
        str_cats (buffer, "nftp.ico");
        if (access (buffer, R_OK) == 0)
            set_icon (buffer);
    }

    if (main_menu != NULL)
    {
        menu_activate (main_menu);
        adjust_menu_status ();
    }
    
    display.dir_mode = options.defaultdirmode;
    display.view_mode = VIEW_CONTROL;
    
    display.rshift = 0;
    display.lshift = 0;
    display.tabsize = 8;
    if (options.slowlink)
        set_view_mode (VIEW_REMOTE);
    else
        set_view_mode (VIEW_CONTROL);
    site.maxndir = 1024;
    site.dir = malloc (sizeof(directory)*site.maxndir);

    // ignore "broken PIPE" signals
    signal (SIGPIPE, SIG_IGN);

    set_window_name ("NFTP%s(C) Copyright Sergey Ayukov", NFTP_VERSION);

    local.dir.files = NULL;
    local.sortmode = abs (options.default_localsort);
    if (options.default_localsort >= 0)
        local.sortdirection = 1;
    else
        local.sortdirection = -1;
    build_local_filelist (NULL);

    site.batch_mode = FALSE;
    site.chunks = NULL;

    PutLineIntoResp2 ("NFTP Version%s(%s, %s) -- %s", NFTP_VERSION, __DATE__, __TIME__, fl_opt.platform_name);
    PutLineIntoResp1 ("Copyright (C) 1994-2003 Sergey Ayukov <*****@*****.**>");
    PutLineIntoResp1 ("Portions Copyright (C) Eric Young <*****@*****.**>");
    //PutLineIntoResp1 ("Portions Copyright (C) Martin Nicolay <*****@*****.**>");
    status.usage_interval = 0;
    if (!fl_opt.has_osmenu)
        PutLineIntoResp1 (M("Press F9 or Ctrl-F for menu"));
    update (1);

    if (options.firewall_type != 0)
    {
        if (options.fire_server[0] == '\0')
        {
            fly_ask_ok (ASK_WARN, M("Firewall proxy host isn't specified in NFTP.INI"));
            options.firewall_type = 0;
        }
        else
        {
            if (strspn (options.fire_server, " .0123456789") == strlen (options.fire_server))
            {
                firewall.fwip = inet_addr (options.fire_server);
            }
            else
            {
                PutLineIntoResp2 (M("Looking up '%s'"), options.fire_server);
                remote = gethostbyname (options.fire_server);
                if (remote == NULL)
                {
                    PutLineIntoResp2 (M("Cannot find '%s'"), options.fire_server);
                    options.firewall_type = 0;
                }
                else
                {
                    firewall.fwip = *((unsigned long *)(remote->h_addr));
                    PutLineIntoResp2 (M("Found '%s'"), remote->h_name);
                }
            }
        }
    }

    // read password cache
    psw_read ();
        
    // analyze arguments
    switch (action)
    {
    case 0:
        if (options.download_path != NULL)
        {
            set_local_path (options.download_path);
        }
        else
        {
            p = cfg_get_string (CONFIG_NFTP, "", "local-directory");
            if (p[0] != '\0')
                set_local_path (p);
        }
        build_local_filelist (NULL);
        switch (options.start_prompt)
        {
        case 1:  return FMSG_BASE_MENU + KEY_GEN_LOGIN;
        case 2:  return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS;
        case 3:  return FMSG_BASE_MENU + KEY_GEN_HISTORY;
        case 5:  return FMSG_BASE_MENU + KEY_MENU;
        }
        return 0;
        
    case ACTION_DOWNLOAD:
    case ACTION_UPLOAD:
        oldmode = site.batch_mode;
        site.batch_mode = TRUE;
        if (action == ACTION_DOWNLOAD) rc = do_get (optarg1);
        if (action == ACTION_UPLOAD) rc = do_put (optarg1);
        //set_view_mode (VIEW_CONTROL);
        //update (1);
        if (rc && !cmdline.batchmode)
            fly_ask_ok (0, M("Transfer of '%s' has failed"), optarg1);
        if ((disc_after && rc == 0) || cmdline.batchmode)
        {
            Logoff ();
            terminate ();
            exit (0);
        }
        site.batch_mode = oldmode;
        return 0;

    case ACTION_CMDLIST:
        rc = runscript (optarg1);
        return 0;

    case ACTION_NICK_BOOK:
    case ACTION_NICK_HIST:
        if (action == ACTION_NICK_BOOK && bookmark_nickname (optarg1, &u) == 0) return 0;
        if (action == ACTION_NICK_HIST && history_nickname (optarg1, &u) == 0) return 0;
        rc = Login (&u);
        if (rc) return 0;
        if (options.login_bell) Bell (3);
        return 0;

    case ACTION_OPEN_BOOKMARKS:
        return FMSG_BASE_MENU + KEY_GEN_BOOKMARKS;
        
    case ACTION_OPEN_HISTORY:
        return FMSG_BASE_MENU + KEY_GEN_HISTORY;

    case ACTION_LOGIN:
        // if download_path was specified in nftp.ini, set it now
        if (options.download_path != NULL)
            set_local_path (options.download_path);
        build_local_filelist (NULL);
        parse_url (optarg1, &u);
        rc = Login (&u);
        // attempt to download file if chdir failed
        /*if (site.set_up && strcmp (site.u.pathname, RCURDIR.name) != 0)
        {
            rc = do_get (optarg1);
        }
        if (rc) return 0;
        */
        if (options.login_bell) Bell (3);
        return 0;

    case ACTION_TESTONLY:
        terminate ();
        exit (0);
    }
    fly_error ("internal error in init()");
    return 0;
}