Ejemplo n.º 1
0
void hexchat_globally_back()
{
    std::vector<int> xs;
    std::vector<int>::iterator xsi;
    hexchat_list *xl = hexchat_list_get(ph, "channels");

    if(xl)
    {
        while(hexchat_list_next(ph, xl))
        {
            xsi = std::find(xs.begin(), xs.end(), hexchat_list_int(ph, xl, "id"));

            if((xsi == xs.end()) &&
                    ((strlen(hexchat_list_str(ph, xl, "server")) > 0) ||
                     (strlen(hexchat_list_str(ph, xl, "channel")) > 0)))
            {
                xs.push_back(hexchat_list_int(ph, xl, "id"));
                hexchat_set_context(ph, (hexchat_context *)hexchat_list_str(ph, xl, "context"));
                hexchat_back();
            }
        }

        hexchat_list_free(ph, xl);
    }
}
Ejemplo n.º 2
0
struct _hexchat_context *hexchat_find_server(int find_id)
{
    hexchat_context *xc;
    hexchat_list *xl = hexchat_list_get(ph, "channels");
    int id;

    if(!xl)
        return NULL;

    while(hexchat_list_next(ph, xl))
    {
        id = hexchat_list_int(ph, xl, "id");

        if(id == -1)
        {
            return NULL;
        }
        else if(id == find_id)
        {
            xc = (hexchat_context *)hexchat_list_str(ph, xl, "context");

            hexchat_list_free(ph, xl);

            return xc;
        }
    }

    hexchat_list_free(ph, xl);

    return NULL;
}
Ejemplo n.º 3
0
static int
get_current_context_type (void)
{
    int type = 0;
    hexchat_list *list;
    hexchat_context *cur_ctx;

    list = hexchat_list_get (ph, "channels");
    if (!list)
        return 0;

    cur_ctx = hexchat_get_context (ph);

    while (hexchat_list_next (ph, list))
    {
        if ((hexchat_context*)hexchat_list_str (ph, list, "context") == cur_ctx)
        {
            type = hexchat_list_int (ph, list, "type");
            break;
        }
    }

    hexchat_list_free (ph, list);
    return type;
}
Ejemplo n.º 4
0
Archivo: perl.c Proyecto: Farow/hexchat
static SV *
list_item_to_sv ( hexchat_list *list, const char *const *fields )
{
	HV *hash = newHV();
	SV *field_value;
	const char *field;
	int field_index = 0;
	const char *field_name;
	int name_len;

	while (fields[field_index] != NULL) {
		field_name = fields[field_index] + 1;
		name_len = strlen (field_name);

		switch (fields[field_index][0]) {
		case 's':
			field = hexchat_list_str (ph, list, field_name);
			if (field != NULL) {
				field_value = newSVpvn (field, strlen (field));
			} else {
				field_value = &PL_sv_undef;
			}
			break;
		case 'p':
			field_value = newSViv (PTR2IV (hexchat_list_str (ph, list,
																	 field_name)));
			break;
		case 'i':
			field_value = newSVuv (hexchat_list_int (ph, list, field_name));
			break;
		case 't':
			field_value = newSVnv (hexchat_list_time (ph, list, field_name));
			break;
		default:
			field_value = &PL_sv_undef;
		}
		(void)hv_store (hash, field_name, name_len, field_value, 0);
		field_index++;
	}
	return sv_2mortal (newRV_noinc ((SV *) hash));
}
Ejemplo n.º 5
0
static int
netdata_cb (char *word[], char *word_eol[], void *userdata)
{
	char netdata[bsize];
	char format[bsize];
	unsigned long long bytes_recv;
	unsigned long long bytes_sent;
	
	if (*word[2] == '\0')
	{
		hexchat_printf (ph, "%s\tYou must specify a network device (e.g. /NETDATA eth0)!", name);
		return HEXCHAT_EAT_ALL;
	}

	if (xs_parse_netdev (word[2], &bytes_recv, &bytes_sent) != 0)
	{
		hexchat_printf (ph, "%s\tERROR in parse_netdev", name);
		return HEXCHAT_EAT_ALL;
	}

	bytes_recv /= 1024;
	bytes_sent /= 1024;
	
	snprintf (netdata, bsize, "%s: %.1f MB Recieved, %.1f MB Sent", word[2], (double)bytes_recv/1024.0, (double)bytes_sent/1024.0);
	hexchat_pluginpref_get_str (ph, "format", format);
	format_output ("Netdata", netdata, format);

	if (hexchat_list_int (ph, NULL, "type") >= 2)
	{
		hexchat_commandf (ph, "SAY %s", netdata);
	}
	else
	{
		hexchat_printf (ph, "%s", netdata);
	}
	
	return HEXCHAT_EAT_ALL;
}
Ejemplo n.º 6
0
static int
printInfo (char *word[], char *word_eol[], void *user_data)
{
	/* query WMI info only at the first time SysInfo is called, then cache it to save time */
	if (firstRun)
	{
		hexchat_printf (ph, "%s first execution, querying and caching WMI info...\n", name);
		wmiOs = getWmiInfo (0);
		wmiCpu = getWmiInfo (1);
		wmiVga = getWmiInfo (2);
		firstRun = 0;
	}
	if (hexchat_list_int (ph, NULL, "type") >= 2)
	{
		/* uptime will work correctly for up to 50 days, should be enough */
		hexchat_commandf (ph, "ME ** SysInfo ** Client: HexChat %s (x%d) ** OS: %s ** CPU: %s (%s) ** RAM: %s ** VGA: %s ** Uptime: %.2f Hours **",
			hexchat_get_info (ph, "version"),
			getCpuArch (),
			wmiOs,
			wmiCpu,
			getCpuMhz (),
			getMemoryInfo (),
			wmiVga, (float) GetTickCount() / 1000 / 60 / 60);
	}
	else
	{
		hexchat_printf (ph, " * Client:  HexChat %s (x%d)\n", hexchat_get_info (ph, "version"), getCpuArch ());
		hexchat_printf (ph, " * OS:      %s\n", wmiOs);
		hexchat_printf (ph, " * CPU:     %s (%s)\n", wmiCpu, getCpuMhz ());
		hexchat_printf (ph, " * RAM:     %s\n", getMemoryInfo ());
		hexchat_printf (ph, " * VGA:     %s\n", wmiVga);
		hexchat_printf (ph, " * Uptime:  %.2f Hours\n", (float) GetTickCount() / 1000 / 60 / 60);
	}

	return HEXCHAT_EAT_HEXCHAT;
}
Ejemplo n.º 7
0
Archivo: lua.c Proyecto: Cynede/hexchat
static inline int list_marshal(lua_State *L, const char *key, hexchat_list *list)
{
	char const *str = hexchat_list_str(ph, list, key);
	int number;
	if(str)
	{
		if(!strcmp(key, "context"))
		{
			hexchat_context **u = lua_newuserdata(L, sizeof(hexchat_context *));
			*u = (hexchat_context *)str;
			luaL_newmetatable(L, "context");
			lua_setmetatable(L, -2);
			return 1;
		}
		lua_pushstring(L, str);
		return 1;
	}
	number = hexchat_list_int(ph, list, key);
	if(number != -1)
	{
		lua_pushinteger(L, number);
		return 1;
	}
	if (list != NULL)
	{
		time_t tm = hexchat_list_time(ph, list, key);
		if(tm != -1)
		{
			lua_pushinteger(L, tm);
			return 1;
		}
	}

	lua_pushnil(L);
	return 1;
}
Ejemplo n.º 8
0
HMENU setServerMenu()
{
    HMENU sTemp = CreateMenu();
    TCHAR wszServer[128];
    TCHAR wszNick[128];
    TCHAR wszMenuEntry[256];

    std::vector<int> xs;
    std::vector<int>::iterator xsi;
    hexchat_list *xl = hexchat_list_get(ph, "channels");

    AppendMenu(sTemp, MF_STRING, ACT_AWAY, _T("Set Globally Away"));
    AppendMenu(sTemp, MF_STRING, ACT_BACK, _T("Set Globally Back"));
    AppendMenu(sTemp, MF_SEPARATOR, 0, NULL);

    if(xl)
    {
        while(hexchat_list_next(ph, xl))
        {
            xsi = std::find(xs.begin(), xs.end(), hexchat_list_int(ph, xl, "id"));

            if( (xsi == xs.end()) &&
                    ((strlen(hexchat_list_str(ph, xl, "server")) > 0) ||
                     (strlen(hexchat_list_str(ph, xl, "channel")) > 0)))
            {
                hexchat_set_context(ph, (hexchat_context *)hexchat_list_str(ph, xl, "context"));
                xs.push_back(hexchat_list_int(ph, xl, "id"));

                char *network	= _strdup(hexchat_list_str(ph, xl, "network"));
                char *server	= _strdup(hexchat_list_str(ph, xl, "server"));
                char *nick		= _strdup(hexchat_get_info(ph, "nick"));

                if(network != NULL)
                {
                    ConvertString(network, wszServer, 128);
                }
                else
                {
                    ConvertString(server, wszServer, 128);
                }

                if(server != NULL)
                {
                    ConvertString(nick, wszNick, 128);
                    _sntprintf(wszMenuEntry, 256, _T("%s @ %s\0"), wszNick, wszServer);

                    if(!hexchat_get_info(ph, "away"))
                    {
                        AppendMenu(sTemp, MF_STRING, (hexchat_list_int(ph, xl, "id") + 1), wszMenuEntry);
                    }
                    else
                    {
                        AppendMenu(sTemp, (MF_CHECKED | MF_STRING), (hexchat_list_int(ph, xl, "id") + 1), wszMenuEntry);
                    }
                }

                free(network);
                free(server);
                free(nick);
            }
        }

        hexchat_list_free(ph, xl);
    }

    return sTemp;
}
Ejemplo n.º 9
0
static int
sysinfo_cb (char *word[], char *word_eol[], void *userdata)
{
	error_printed = 0;
	int announce = 0;
	int buffer;
	char format[bsize];

	if (!hexchat_pluginpref_get_str (ph, "format", format))
	{
		hexchat_printf (ph, "%s\tError reading config file!", name);
		return HEXCHAT_EAT_ALL;
	}

	if (hexchat_list_int (ph, NULL, "type") >= 2)
	{
		announce = 1;
	}

	if (!g_ascii_strcasecmp ("HELP", word[2]))
	{
		hexchat_printf (ph, sysinfo_help);
		return HEXCHAT_EAT_ALL;
	}
	else if (!g_ascii_strcasecmp ("LIST", word[2]))
	{
		list_settings ();
		return HEXCHAT_EAT_ALL;
	}
	else if (!g_ascii_strcasecmp ("SET", word[2]))
	{
		if (!g_ascii_strcasecmp ("", word_eol[4]))
		{
			hexchat_printf (ph, "%s\tEnter a value!\n", name);
			return HEXCHAT_EAT_ALL;
		}
		if (!g_ascii_strcasecmp ("format", word[3]))
		{
			hexchat_pluginpref_set_str (ph, "format", word_eol[4]);
			hexchat_printf (ph, "%s\tformat is set to: %s\n", name, word_eol[4]);
		}
		else if (!g_ascii_strcasecmp ("percent", word[3]))
		{
			buffer = atoi (word[4]);	/* don't use word_eol, numbers must not contain spaces */

			if (buffer > 0 && buffer < INT_MAX)
			{
				hexchat_pluginpref_set_int (ph, "percent", buffer);
				hexchat_printf (ph, "%s\tpercent is set to: %d\n", name, buffer);
			}
			else
			{
				hexchat_printf (ph, "%s\tInvalid input!\n", name);
			}
		}
		else if (!g_ascii_strcasecmp ("pciids", word[3]))
		{
			hexchat_pluginpref_set_str (ph, "pciids", word_eol[4]);
			hexchat_printf (ph, "%s\tpciids is set to: %s\n", name, word_eol[4]);
		}
		else
		{
			hexchat_printf (ph, "%s\tInvalid variable name! Use 'pciids', 'format' or 'percent'!\n", name);
			return HEXCHAT_EAT_ALL;
		}

		return HEXCHAT_EAT_ALL;
	}
	else if (!g_ascii_strcasecmp ("RESET", word[2]))
	{
		reset_settings ();
		hexchat_printf (ph, "%s\tSettings have been restored to defaults.\n", name);
		return HEXCHAT_EAT_ALL;
	}
	else if (!g_ascii_strcasecmp ("OS", word[2]))
	{
		print_os (announce, format);
		return HEXCHAT_EAT_ALL;
	}
	else if (!g_ascii_strcasecmp ("DISTRO", word[2]))
	{
		print_distro (announce, format);
		return HEXCHAT_EAT_ALL;
	}
	else if (!g_ascii_strcasecmp ("CPU", word[2]))
	{
		print_cpu (announce, format);
		return HEXCHAT_EAT_ALL;
	}
	else if (!g_ascii_strcasecmp ("RAM", word[2]))
	{
		print_ram (announce, format);
		return HEXCHAT_EAT_ALL;
	}
	else if (!g_ascii_strcasecmp ("DISK", word[2]))
	{
		print_disk (announce, format);
		return HEXCHAT_EAT_ALL;
	}
	else if (!g_ascii_strcasecmp ("VGA", word[2]))
	{
		print_vga (announce, format);
		return HEXCHAT_EAT_ALL;
	}
	else if (!g_ascii_strcasecmp ("SOUND", word[2]))
	{
		print_sound (announce, format);
		return HEXCHAT_EAT_ALL;
	}
	else if (!g_ascii_strcasecmp ("ETHERNET", word[2]))
	{
		print_ethernet (announce, format);
		return HEXCHAT_EAT_ALL;
	}
	else if (!g_ascii_strcasecmp ("UPTIME", word[2]))
	{
		print_uptime (announce, format);
		return HEXCHAT_EAT_ALL;
	}
	else if (!g_ascii_strcasecmp ("", word[2]))
	{
		print_summary (announce, format);
		return HEXCHAT_EAT_ALL;
	}
	else
	{
		hexchat_printf (ph, sysinfo_help);
		return HEXCHAT_EAT_ALL;
	}
}
Ejemplo n.º 10
0
static int
netstream_cb (char *word[], char *word_eol[], void *userdata)
{
	char netstream[bsize];
	char mag_r[5];
	char mag_s[5];
	char format[bsize];
	unsigned long long bytes_recv;
	unsigned long long bytes_sent;
	unsigned long long bytes_recv_p;
	unsigned long long bytes_sent_p;

	struct timespec ts = {1, 0};

	if (*word[2] == '\0')
	{
		hexchat_printf (ph, "%s\tYou must specify a network device (e.g. /NETSTREAM eth0)!", name);
		return HEXCHAT_EAT_ALL;
	}

	if (xs_parse_netdev(word[2], &bytes_recv, &bytes_sent) != 0)
	{
		hexchat_printf (ph, "%s\tERROR in parse_netdev", name);
		return HEXCHAT_EAT_ALL;
	}

	while (nanosleep (&ts, &ts) < 0);

	if (xs_parse_netdev(word[2], &bytes_recv_p, &bytes_sent_p) != 0)
	{
		hexchat_printf (ph, "%s\tERROR in parse_netdev", name);
		return HEXCHAT_EAT_ALL;
	}

	bytes_recv = (bytes_recv_p - bytes_recv);
	bytes_sent = (bytes_sent_p - bytes_sent);

	if (bytes_recv > 1024)
	{
		bytes_recv /= 1024;
		snprintf (mag_r, 5, "KB/s");
	}
	else
	{
		snprintf (mag_r, 5, "B/s");
	}

	if (bytes_sent > 1024)
	{
		bytes_sent /= 1024;
		snprintf (mag_s, 5, "KB/s");
	}
	else
	{
		snprintf (mag_s, 5, "B/s");
	}

	snprintf (netstream, bsize, "%s: Receiving %llu %s, Sending %llu %s", word[2], bytes_recv, mag_r, bytes_sent, mag_s);
	hexchat_pluginpref_get_str (ph, "format", format);
	format_output ("Netstream", netstream, format);

	if (hexchat_list_int (ph, NULL, "type") >= 2)
	{
		hexchat_commandf (ph, "SAY %s", netstream);
	}
	else
	{
		hexchat_printf (ph, "%s", netstream);
	}

	return HEXCHAT_EAT_ALL;
}
Ejemplo n.º 11
0
static int get_current_context_type (void)
{
	return hexchat_list_int (ph, NULL, "type");
}