static int print_os (int announce, char* format) { char buffer[bsize]; char user[bsize]; char host[bsize]; char kernel[bsize]; if (xs_parse_os (user, host, kernel) != 0) { hexchat_printf (ph, "%s\tERROR in parse_os()", name); return HEXCHAT_EAT_ALL; } snprintf (buffer, bsize, "%s@%s, %s", user, host, kernel); format_output ("OS", buffer, format); if (announce) { hexchat_commandf (ph, "SAY %s", buffer); } else { hexchat_printf (ph, "%s", buffer); } return HEXCHAT_EAT_ALL; }
static int dccoffer_cb (char *word[], void *userdata) { int result; struct stat buffer; /* buffer for storing file info */ char sum[65]; /* buffer for checksum */ result = stat (word[3], &buffer); if (result == 0) /* stat returns 0 on success */ { if (buffer.st_size <= (unsigned long long) get_limit () * 1048576) { sha256_file (word[3], sum); /* word[3] is the full filename */ hexchat_commandf (ph, "quote PRIVMSG %s :SHA-256 checksum for %s (remote): %s", word[2], word[1], sum); } else { hexchat_set_context (ph, hexchat_find_context (ph, NULL, word[3])); hexchat_printf (ph, "quote PRIVMSG %s :SHA-256 checksum for %s (remote): (size limit reached, no checksum calculated)", word[2], word[1]); } } else { hexchat_printf (ph, "File access error!\n"); } return HEXCHAT_EAT_NONE; }
static void cmd_start (const char *nick) { if (get_current_context_type () != 3) { hexchat_print (ph, "OTR: You can only use OTR in a dialog\n"); return; } hexchat_commandf (ph, "quote PRIVMSG %s :?OTRv23?", nick); }
void hexchat_away(TCHAR *tszAway) { char szTemp[512]; char szAway[512]; ConvertString(tszAway, szAway, 512); _snprintf(szTemp, 512, szAway); check_special_chars(szTemp); hexchat_commandf(ph, "AWAY %s\0", szTemp); }
static int print_uptime (int announce, char* format) { char buffer[bsize]; int weeks; int days; int hours; int minutes; int seconds; if (xs_parse_uptime (&weeks, &days, &hours, &minutes, &seconds)) { hexchat_printf (ph, "%s\tERROR in parse_uptime()", name); return HEXCHAT_EAT_ALL; } if (minutes != 0 || hours != 0 || days != 0 || weeks != 0) { if (hours != 0 || days != 0 || weeks != 0) { if (days !=0 || weeks != 0) { if (weeks != 0) { snprintf (buffer, bsize, "%dw %dd %dh %dm %ds", weeks, days, hours, minutes, seconds); } else { snprintf (buffer, bsize, "%dd %dh %dm %ds", days, hours, minutes, seconds); } } else { snprintf (buffer, bsize, "%dh %dm %ds", hours, minutes, seconds); } } else { snprintf (buffer, bsize, "%dm %ds", minutes, seconds); } } format_output ("Uptime", buffer, format); if (announce) { hexchat_commandf (ph, "SAY %s", buffer); } else { hexchat_printf (ph, "%s", buffer); } return HEXCHAT_EAT_ALL; }
static int connect_cb (char *word[], void *userdata) { if (get_info ()) { hexchat_printf (ph, "%s\tSASL enabled\n", name); hexchat_commandf (ph, "QUOTE CAP REQ :sasl"); } return HEXCHAT_EAT_NONE; }
static int authend_cb (char *word[], char *word_eol[], void *userdata) { if (get_info ()) { /* omit cryptic server message parts */ hexchat_printf (ph, "%s\t%s\n", name, ++word_eol[4]); hexchat_commandf (ph, "QUOTE CAP END"); } return HEXCHAT_EAT_ALL; }
void CWMPADialog::OnDblclkSonglist() { // TODO: Add your control notification handler code here int index = m_SongListBox.GetCurSel(); m_WMP.GetControls().playItem(m_WMP.GetCurrentPlaylist().GetItem(index)); if (autoAnnounce) { hexchat_commandf(ph, "me is playing %s", (LPCTSTR) wmpaGetSongTitle()); } else { hexchat_printf(ph, "WMPA: Playing %s", (LPCTSTR) wmpaGetSongTitle()); } }
static int cap_cb (char *word[], char *word_eol[], void *userdata) { if (get_info ()) { /* FIXME test sasl cap */ /* this is visible in the rawlog in case someone needs it, otherwise it's just noise */ /* hexchat_printf (ph, "%s\t%s\n", name, word_eol[1]); */ hexchat_commandf (ph, "QUOTE AUTHENTICATE PLAIN"); } return HEXCHAT_EAT_ALL; }
void CWMPADialog::OnCurrentItemChangeWmp(LPDISPATCH pdispMedia) { // TODO: Add your control notification handler code here int state = m_WMP.GetPlayState(); if (state == 3) { // Playing if (autoAnnounce) { hexchat_commandf(ph, "me is playing %s", (LPCTSTR) wmpaGetSongTitle()); } else { hexchat_printf(ph, "WMPA: Playing %s", (LPCTSTR) wmpaGetSongTitle()); } } SelectCurrentSong(); }
/** * Called when a message is to be sent. */ static int handle_outgoing(char *word[], char *word_eol[], void *userdata) { const char *own_nick; // Encrypt the message if possible const char *channel = hexchat_get_info(ph, "channel"); char *encrypted = fish_encrypt_for_nick(channel, word_eol[1]); if (!encrypted) return HEXCHAT_EAT_NONE; // Display message own_nick = hexchat_get_info(ph, "nick"); hexchat_emit_print(ph, "Your Message", own_nick, word_eol[1], NULL); // Send message hexchat_commandf(ph, "PRIVMSG %s :+OK %s", channel, encrypted); free(encrypted); return HEXCHAT_EAT_HEXCHAT; }
static int print_cpu (int announce, char* format) { char model[bsize]; char vendor[bsize]; char cache[bsize]; char buffer[bsize]; unsigned int count; double freq; int giga = 0; if (xs_parse_cpu (model, vendor, &freq, cache, &count) != 0) { hexchat_printf (ph, "%s\tERROR in parse_cpu()", name); return HEXCHAT_EAT_ALL; } if (freq > 1000) { freq /= 1000; giga = 1; } if (giga) { snprintf (buffer, bsize, "%d x %s (%s) @ %.2fGHz w/ %s L2 Cache", count, model, vendor, freq, cache); } else { snprintf (buffer, bsize, "%d x %s (%s) @ %.0fMHz w/ %s L2 Cache", count, model, vendor, freq, cache); } format_output ("CPU", buffer, format); if (announce) { hexchat_commandf (ph, "SAY %s", buffer); } else { hexchat_printf (ph, "%s", buffer); } return HEXCHAT_EAT_ALL; }
static int print_disk (int announce, char* format) { char string[bsize] = {0,}; #if 0 if (*word == '\0') { if (xs_parse_df (NULL, string)) { hexchat_printf (ph, "ERROR in parse_df"); return HEXCHAT_EAT_ALL; } } else { if (xs_parse_df (*word, string)) { hexchat_printf (ph, "ERROR in parse_df"); return HEXCHAT_EAT_ALL; } } #endif if (xs_parse_df (NULL, string)) { hexchat_printf (ph, "%s\tERROR in parse_df", name); return HEXCHAT_EAT_ALL; } format_output ("Disk", string, format); if (announce) { hexchat_commandf (ph, "SAY %s", string); } else { hexchat_printf (ph, "%s", string); } return HEXCHAT_EAT_ALL; }
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; }
static int print_distro (int announce, char* format) { char name[bsize]; if (xs_parse_distro (name) != 0) { hexchat_printf (ph, "%s\tERROR in parse_distro()!", name); return HEXCHAT_EAT_ALL; } format_output("Distro", name, format); if (announce) { hexchat_commandf (ph, "SAY %s", name); } else { hexchat_printf (ph, "%s", name); } return HEXCHAT_EAT_ALL; }
static int print_ethernet (int announce, char* format) { char ethernet_card[bsize]; if (xs_parse_ether (ethernet_card)) { strncpy (ethernet_card, "None found", bsize); } format_output ("Ethernet", ethernet_card, format); if (announce) { hexchat_commandf (ph, "SAY %s", ethernet_card); } else { hexchat_printf (ph, "%s", ethernet_card); } return HEXCHAT_EAT_ALL; }
static int server_cb (char *word[], char *word_eol[], void *userdata) { size_t len; char* buf; char* enc; sasl_info* p; if (strcmp ("AUTHENTICATE", word[1]) == 0 && strcmp ("+", word[2]) == 0) { p = get_info (); if (!p) { return HEXCHAT_EAT_NONE; } hexchat_printf (ph, "%s\tAuthenticating as %s\n", name, p->login); len = strlen (p->login) * 2 + 2 + strlen (p->password); buf = (char*) malloc (len + 1); strcpy (buf, p->login); strcpy (buf + strlen (p->login) + 1, p->login); strcpy (buf + strlen (p->login) * 2 + 2, p->password); enc = g_base64_encode ((unsigned char*) buf, len); /* hexchat_printf (ph, "AUTHENTICATE %s\}", enc); */ hexchat_commandf (ph, "QUOTE AUTHENTICATE %s", enc); free (enc); free (buf); return HEXCHAT_EAT_ALL; } return HEXCHAT_EAT_NONE; }
static int print_vga (int announce, char* format) { char vid_card[bsize]; char agp_bridge[bsize]; char buffer[bsize]; int ret; if ((ret = xs_parse_video (vid_card)) != 0) { hexchat_printf (ph, "%s\tERROR in parse_video! %d", name, ret); return HEXCHAT_EAT_ALL; } if (xs_parse_agpbridge (agp_bridge) != 0) { snprintf (buffer, bsize, "%s", vid_card); } else { snprintf (buffer, bsize, "%s @ %s", vid_card, agp_bridge); } format_output ("VGA", buffer, format); if (announce) { hexchat_commandf (ph, "SAY %s", buffer); } else { hexchat_printf (ph, "%s", buffer); } return HEXCHAT_EAT_ALL; }
static int print_sound (int announce, char* format) { char sound[bsize]; if (xs_parse_sound (sound) != 0) { hexchat_printf (ph, "%s\tERROR in parse_asound()!", name); return HEXCHAT_EAT_ALL; } format_output ("Sound", sound, format); if (announce) { hexchat_commandf (ph, "SAY %s", sound); } else { hexchat_printf (ph, "%s", sound); } return HEXCHAT_EAT_ALL; }
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; }
static int command_lua(char *word[], char *word_eol[], void *userdata) { if(!strcmp(word[2], "load")) { load_script(word[3]); } else if(!strcmp(word[2], "unload")) { if(!unload_script(word[3])) hexchat_printf(ph, "Could not find a script by the name '%s'", word[3]); } else if(!strcmp(word[2], "reload")) { if(!reload_script(word[3])) hexchat_printf(ph, "Could not find a script by the name '%s'", word[3]); } else if(!strcmp(word[2], "exec")) { if(interp) inject_string(interp, word_eol[3]); } else if(!strcmp(word[2], "inject")) { script_info *script = get_script_by_file(word[3]); if (script) { inject_string(script, word_eol[4]); } else { hexchat_printf(ph, "Could not find a script by the name '%s'", word[3]); } } else if(!strcmp(word[2], "reset")) { if(interp) { if(interp->status & STATUS_ACTIVE) { interp->status |= STATUS_DEFERRED_RELOAD; } else { run_unload_hooks(interp, NULL); destroy_interpreter(); create_interpreter(); } } } else if(!strcmp(word[2], "list")) { guint i; hexchat_print(ph, "Name Version Filename Description\n" "---- ------- -------- -----------\n"); for(i = 0; i < scripts->len; i++) { script_info *info = scripts->pdata[i]; char *basename = g_path_get_basename(info->filename); hexchat_printf(ph, "%-16s %-8s %-20s %-10s\n", info->name, info->version, basename, info->description); g_free(basename); } if(interp) hexchat_printf(ph, "%-16s %-8s", interp->name, plugin_version); } else if(!strcmp(word[2], "console")) { hexchat_commandf(ph, "query %s", console_tab); } else { hexchat_command(ph, "help lua"); } return HEXCHAT_EAT_ALL; }
static int winamp(const char *const word[], const char *const word_eol[], void *userdata) { char current_play[2048], *p; char p_esc[2048]; char cur_esc[2048]; char truc[2048]; HWND hwndWinamp = FindWindowW(L"Winamp v1.x",NULL); if (hwndWinamp) { { if (!stricmp("PAUSE", word[2])) { if (SendMessageW(hwndWinamp,WM_USER, 0, 104)) { SendMessageW(hwndWinamp, WM_COMMAND, 40046, 0); if (SendMessageW(hwndWinamp, WM_USER, 0, 104) == PLAYING) hexchat_print(ph, "Winamp: playing"); else hexchat_print(ph, "Winamp: paused"); } } else if (!stricmp("STOP", word[2])) { SendMessageW(hwndWinamp, WM_COMMAND, 40047, 0); hexchat_print(ph, "Winamp: stopped"); } else if (!stricmp("PLAY", word[2])) { SendMessageW(hwndWinamp, WM_COMMAND, 40045, 0); hexchat_print(ph, "Winamp: playing"); } else if (!stricmp("NEXT", word[2])) { SendMessageW(hwndWinamp, WM_COMMAND, 40048, 0); hexchat_print(ph, "Winamp: next playlist entry"); } else if (!stricmp("PREV", word[2])) { SendMessageW(hwndWinamp, WM_COMMAND, 40044, 0); hexchat_print(ph, "Winamp: previous playlist entry"); } else if (!stricmp("START", word[2])) { SendMessageW(hwndWinamp, WM_COMMAND, 40154, 0); hexchat_print(ph, "Winamp: playlist start"); } else if (!word_eol[2][0]) { GetWindowText(hwndWinamp, current_play, sizeof(current_play)); if (strchr(current_play, '-')) { p = current_play + strlen(current_play) - 8; while (p >= current_play) { if (!strnicmp(p, "- Winamp", 8)) break; p--; } if (p >= current_play) p--; while (p >= current_play && *p == ' ') p--; *++p=0; p = strchr(current_play, '.') + 1; song_strcpy(p_esc, p); song_strcpy(cur_esc, current_play); if (p) { sprintf(truc, "me is now playing:%s", p_esc); } else { sprintf(truc, "me is now playing:%s", cur_esc); } hexchat_commandf(ph, truc); } else hexchat_print(ph, "Winamp: Nothing being played."); } else hexchat_printf(ph, "Usage: /WINAMP [PAUSE|PLAY|STOP|NEXT|PREV|START]\n"); } } else { hexchat_print(ph, "Winamp not found.\n"); } return HEXCHAT_EAT_ALL; }
void irc_send_message (IRC_CTX *ircctx, const char *recipient, char *msg) { hexchat_commandf (ph, "PRIVMSG %s :%s", recipient, msg); }
// Displays current song and controls Winamp static int wp_cb(char *word[], char *word_eol[], void *userdata) { HWND hwndWinamp = NULL; long int bitrate, length, elapsed, minutes, seconds, eminutes, eseconds, samplerate, nbchannels; size_t convertedChars = 0; char elapsedtime[7]; char totaltime[7]; std::wstring *strTitle; std::string this_title; LPCWSTR winName=L"Winamp v1.x"; if ((hwndWinamp = FindWindow(winName,NULL)) == NULL) hexchat_print(ph, "Winamp window not found. Is Winamp running?\n"); else // Winamp's running { // Seems buggy when Winamp2's agent is running, and Winamp not (or Winamp3) -> crashes XChat. SendMessage(hwndWinamp, WM_USER, (WPARAM)0, (LPARAM)IPC_GETLISTPOS); strTitle=GetCurrentSongsName(hwndWinamp); this_title=to_utf8(strTitle->c_str(),strTitle->length()); //xchat_printf(ph, "Title: %s\n", this_title); // Get samplerate if ((samplerate = SendMessage(hwndWinamp, WM_USER, (WPARAM)0, (LPARAM)IPC_GETINFO)) == 0) { hexchat_print(ph, "Could not get current song's samplerate... !?\n"); return HEXCHAT_EAT_ALL; } if (samplerate<8000) { samplerate *= 1000; } // Get bitrate if ((bitrate = SendMessage(hwndWinamp, WM_USER, (WPARAM)1, (LPARAM)IPC_GETINFO)) == 0) { hexchat_print(ph, "Could not get current song's bitrate... !?\n"); return HEXCHAT_EAT_ALL; } // Get number of audio channels if ((nbchannels = SendMessage(hwndWinamp, WM_USER, (WPARAM)2, (LPARAM)IPC_GETINFO)) == 0) { hexchat_print(ph, "Could not get the number of channels... !?\n"); return HEXCHAT_EAT_ALL; } // Get current track's length (in seconds). if ((length = SendMessage(hwndWinamp, WM_USER, (WPARAM)1, (LPARAM)IPC_GETOUTPUTTIME)) == 0) { // Could be buggy when streaming audio or video, returned length is unexpected; // How to detect is Winamp is streaming, and display ??:?? in that case? hexchat_print(ph, "Could not get current song's length... !?\n"); return HEXCHAT_EAT_ALL; } else { minutes = length/60; seconds = length%60; if (seconds>9) sprintf(totaltime, "%d:%d", minutes, seconds); else sprintf(totaltime, "%d:0%d", minutes, seconds); } // Get position of current track (in milliseconds). // This tends to not work when the command to play the next track is spammed. // Never mind. It works if it's ignored. //if ((elapsed = SendMessage(hwndWinamp, WM_USER, 0, IPC_GETOUTPUTTIME)) == 0) //{ elapsed = SendMessage(hwndWinamp, WM_USER, 0, IPC_GETOUTPUTTIME); // Ignore it. It works anyway. // xchat_print(ph, "Could not get current song's elapsed time... !?\n"); // return XCHAT_EAT_ALL; //} //else //{ eminutes = (elapsed / 1000) / 60; /* kinda stupid sounding, but e is for elapsed */ eseconds = (elapsed / 1000) % 60; //xchat_printf(ph, "elapsed: %d\neminutes: %d\neseconds: %d\n", elapsed, eminutes, eseconds); // I'm not sure whether or not I should leave debug prints in the code... if (eseconds > 9) sprintf(elapsedtime, "%d:%d", eminutes, eseconds); else sprintf(elapsedtime, "%d:0%d", eminutes, eseconds); //} // Control of Winamp // Everything's here : http://winamp.com/nsdn/winamp2x/dev/sdk/api.php // The previous url seems dead, see http://forums.winamp.com/showthread.php?threadid=180297 // Display track details if (strcmp(word[2], "") == 0) hexchat_commandf(ph, "dispcurrsong %d %d %d %s %s %s", samplerate, bitrate, nbchannels, elapsedtime, totaltime, this_title.c_str()); // Play previous track else if (strcmp(word[2], "b") == 0) { SendMessage (hwndWinamp, WM_COMMAND, WINAMP_BUTTON1, 0); strTitle=GetCurrentSongsName(hwndWinamp); this_title=to_utf8(strTitle->c_str(),strTitle->length()); hexchat_printf(ph, "Now playing: %s\n", this_title.c_str()); } // Play (or restart current track) else if (strcmp(word[2], "p") == 0) { SendMessage (hwndWinamp, WM_COMMAND, WINAMP_BUTTON2, 0); strTitle=GetCurrentSongsName(hwndWinamp); this_title=to_utf8(strTitle->c_str(),strTitle->length()); hexchat_printf(ph, "Playing: %s\n", this_title.c_str()); } /* // I'd use just 'p' for play/pause, but it looks like foo_winamp_spam isn't working correctly: // Playing is 1; paused should be 3 but is always 1, and stopped is 0. else if (strcmp(word[2], "test") == 0) { // Put int playState; at the beginning of this function playState = SendMessage(hwndWinamp,WM_WA_IPC,1,IPC_ISPLAYING); xchat_printf(ph, "%d", playState); */ // Pause (or play, if paused) else if (strcmp(word[2], "q") == 0) { SendMessage (hwndWinamp, WM_COMMAND, WINAMP_BUTTON3, 0); } else if (strcmp(word[2], "s") == 0) { SendMessage (hwndWinamp, WM_COMMAND, WINAMP_BUTTON4, 0); } else if (strcmp(word[2], "n") == 0) { SendMessage (hwndWinamp, WM_COMMAND, WINAMP_BUTTON5, 0); // Because of overhead between telling it to play a new track and // getting the new track's information Sleep(200); strTitle=GetCurrentSongsName(hwndWinamp); this_title=to_utf8(strTitle->c_str(),strTitle->length()); hexchat_printf(ph, "Now playing: %s\n", this_title.c_str()); } else if (strcmp(word[2], "c") == 0) { hexchat_printf(ph, "Current track: %s[%0d:%d/%0d:%d]\n", this_title, eminutes, eseconds, minutes, seconds); } } return HEXCHAT_EAT_ALL; /* eat this command so xchat and other plugins can't process it */ }
static int print_summary (int announce, char* format) { char sysinfo[bsize]; char buffer[bsize]; char cpu_model[bsize]; char cpu_cache[bsize]; char cpu_vendor[bsize]; char os_host[bsize]; char os_user[bsize]; char os_kernel[bsize]; unsigned long long mem_total; unsigned long long mem_free; unsigned int count; double cpu_freq; int giga = 0; int weeks; int days; int hours; int minutes; int seconds; sysinfo[0] = '\0'; snprintf (buffer, bsize, "%s", hexchat_get_info (ph, "version")); format_output ("HexChat", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (sysinfo)); /* BEGIN OS PARSING */ if (xs_parse_os (os_user, os_host, os_kernel) != 0) { hexchat_printf (ph, "%s\tERROR in parse_os()", name); return HEXCHAT_EAT_ALL; } snprintf (buffer, bsize, "%s", os_kernel); format_output ("OS", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (sysinfo)); /* BEGIN DISTRO PARSING */ if (xs_parse_distro (buffer) != 0) { strncpy (buffer, "Unknown", bsize); } format_output ("Distro", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (sysinfo)); /* BEGIN CPU PARSING */ if (xs_parse_cpu (cpu_model, cpu_vendor, &cpu_freq, cpu_cache, &count) != 0) { hexchat_printf (ph, "%s\tERROR in parse_cpu()", name); return HEXCHAT_EAT_ALL; } if (cpu_freq > 1000) { cpu_freq /= 1000; giga = 1; } if (giga) { snprintf (buffer, bsize, "%d x %s (%s) @ %.2fGHz", count, cpu_model, cpu_vendor, cpu_freq); } else { snprintf (buffer, bsize, "%d x %s (%s) @ %.0fMHz", count, cpu_model, cpu_vendor, cpu_freq); } format_output ("CPU", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (sysinfo)); /* BEGIN MEMORY PARSING */ if (xs_parse_meminfo (&mem_total, &mem_free, 0) == 1) { hexchat_printf (ph, "%s\tERROR in parse_meminfo!", name); return HEXCHAT_EAT_ALL; } snprintf (buffer, bsize, "%s", pretty_freespace ("Physical", &mem_free, &mem_total)); format_output ("RAM", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (sysinfo)); /* BEGIN DISK PARSING */ if (xs_parse_df (NULL, buffer)) { hexchat_printf (ph, "%s\tERROR in parse_df", name); return HEXCHAT_EAT_ALL; } format_output ("Disk", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (buffer)); /* BEGIN VIDEO PARSING */ if (xs_parse_video (buffer)) { hexchat_printf (ph, "%s\tERROR in parse_video", name); return HEXCHAT_EAT_ALL; } format_output ("VGA", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (buffer)); /* BEGIN SOUND PARSING */ if (xs_parse_sound (buffer)) { strncpy (buffer, "Not present", bsize); } format_output ("Sound", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (buffer)); /* BEGIN ETHERNET PARSING */ if (xs_parse_ether (buffer)) { strncpy (buffer, "None found", bsize); } format_output ("Ethernet", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (buffer)); /* BEGIN UPTIME PARSING */ if (xs_parse_uptime (&weeks, &days, &hours, &minutes, &seconds)) { hexchat_printf (ph, "%s\tERROR in parse_uptime()", name); return HEXCHAT_EAT_ALL; } if (minutes != 0 || hours != 0 || days != 0 || weeks != 0) { if (hours != 0 || days != 0 || weeks != 0) { if (days !=0 || weeks != 0) { if (weeks != 0) { snprintf (buffer, bsize, "%dw %dd %dh %dm %ds", weeks, days, hours, minutes, seconds); } else { snprintf (buffer, bsize, "%dd %dh %dm %ds", days, hours, minutes, seconds); } } else { snprintf (buffer, bsize, "%dh %dm %ds", hours, minutes, seconds); } } else { snprintf (buffer, bsize, "%dm %ds", minutes, seconds); } } format_output ("Uptime", buffer, format); strcat (sysinfo, "\017 "); strncat (sysinfo, buffer, bsize - strlen (buffer)); if (announce) { hexchat_commandf (ph, "SAY %s", sysinfo); } else { hexchat_printf (ph, "%s", sysinfo); } return HEXCHAT_EAT_ALL; }
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; }