#include <windows.h>
#include <commctrl.h>
#include "invgg.h"
#include "array.h"
#include "sort.h"
#include "thread.h"
#include "dlgwnd.h"
#include "whois.h"
#include "gethostname.h"
#include "gethostip.h"
#include "..\..\plugs.h"
#include "..\res\resource.h"
void SetList(HWND hList,USER *u,int iItem,int lParam);
BOOL CopyData(HWND hDialog,HWND hEdit);
int CALLBACK SortList(LPARAM lParam1,LPARAM lParam2,LPARAM lParamSort);
void GetHostNameThread(char *szIPAddr);
void GetHostIPThread(char *szHostName);
void WhoIsThread(char *szIPAddr);
extern HINSTANCE hModule;
extern HWND hDialog;
extern CArray userlist;
HWND hName,hIP,hWhois;
char AppName[]=" PowerGG - Inwigilator";
char hostip[32]="";
char hostname[256]="";
char whoisbuf[32000]="";
int sort=0;
//=========================================================================================
BOOL CALLBACK DlgWndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
static HWND hList;
LV_COLUMN lvc;
static HIMAGELIST hSIcon;
int i,size;
USER *u;
static CThread thGetName,thGetIP,thWhoIs;
LOGFONT lf;
static HGDIOBJ hfont;
switch (msg)
{
case WM_INITDIALOG:
hDialog=hWnd;
SendMessage(hWnd,WM_SETICON,ICON_BIG,
(LPARAM)LoadIcon(hModule,MAKEINTRESOURCE(IDI_INVGG)));
SetWindowText(hWnd,AppName);
hList=GetDlgItem(hWnd,IDC_LIST);
hIP=GetDlgItem(hWnd,IDC_IP);
hName=GetDlgItem(hWnd,IDC_NAME);
hWhois=GetDlgItem(hWnd,IDC_WHOIS);
SetWindowText(hIP,hostip);
SetWindowText(hName,hostname);
SetWindowText(hWhois,whoisbuf);
//SetScrollPos(hWhois,SB_VERT,0,TRUE);
//SendMessage(hWhois,WM_VSCROLL,(WPARAM)SB_THUMBPOSITION,0);
hfont=(HGDIOBJ)SendMessage(hWhois,WM_GETFONT,0,0);
GetObject(hfont,sizeof(lf),&lf);
strcpy(lf.lfFaceName,"Courier New");
lf.lfCharSet=OEM_CHARSET;
hfont=CreateFontIndirect(&lf);
SendMessage(hWhois,WM_SETFONT,(WPARAM)hfont,0);
ListView_SetExtendedListViewStyle(hList,LVS_EX_FULLROWSELECT|
LVS_EX_GRIDLINES); //|LVS_EX_FLATSB);
lvc.mask=LVCF_FMT|LVCF_WIDTH|LVCF_TEXT;
lvc.fmt=LVCFMT_LEFT;
lvc.cx=120;
lvc.pszText="Ksywa";
ListView_InsertColumn(hList,0,&lvc);
lvc.cx=76;
lvc.pszText="Numer GG";
ListView_InsertColumn(hList,1,&lvc);
lvc.cx=134;
lvc.pszText="Połączenie";
ListView_InsertColumn(hList,2,&lvc);
lvc.cx=98;
lvc.pszText="IP/ostatnie IP";
ListView_InsertColumn(hList,3,&lvc);
lvc.cx=45;
lvc.pszText="Port";
ListView_InsertColumn(hList,4,&lvc);
lvc.cx=48;
lvc.pszText="Wersja";
ListView_InsertColumn(hList,5,&lvc);
lvc.cx=120;
lvc.pszText="Ostania zmiana";
ListView_InsertColumn(hList,6,&lvc);
hSIcon=ImageList_Create(16,16,ILC_COLOR,1,0);
ImageList_SetBkColor(hSIcon,RGB(0xff,0xff,0xff));
ImageList_AddIcon(hSIcon,LoadIcon(hModule,MAKEINTRESOURCE(IDI_S_NOTAVAIL)));
ImageList_AddIcon(hSIcon,LoadIcon(hModule,MAKEINTRESOURCE(IDI_S_AVAIL)));
ImageList_AddIcon(hSIcon,LoadIcon(hModule,MAKEINTRESOURCE(IDI_S_BUSY)));
ImageList_AddIcon(hSIcon,LoadIcon(hModule,MAKEINTRESOURCE(IDI_S_INVISIBLE)));
ImageList_AddIcon(hSIcon,LoadIcon(hModule,MAKEINTRESOURCE(IDI_S_UNKNOWN)));
ListView_SetImageList(hList,hSIcon,LVSIL_SMALL);
SendMessage(hWnd,UM_SET_LIST,0,0);
return TRUE;
case UM_SET_LIST:
ListView_DeleteAllItems(hList);
size=userlist.Count();
for(i=0;i<size;i++)
{
u=(USER *)userlist.Select(i);
SetList(hList,u,i,i);
}
ListView_SortItems(hList,SortList,sort);
return TRUE;
case WM_NOTIFY:
if(((LPNMHDR)lParam)->code==LVN_ITEMCHANGED)
{
struct sockaddr_in sa;
i=(((LPNMLISTVIEW)lParam)->lParam);
u=(USER *)userlist.Select(i);
if(u->remote_ip)
{
memcpy(&(sa.sin_addr),&(u->remote_ip),4);
SetWindowText(hIP,inet_ntoa(sa.sin_addr));
}
else
{
SetWindowText(hIP,"");
}
SetWindowText(hName,"");
return TRUE;
}
else if(((LPNMHDR)lParam)->code==LVN_COLUMNCLICK)
{
sort=((NM_LISTVIEW *)lParam)->iSubItem;
ListView_SortItems(hList,SortList,sort);
}
return FALSE;
case WM_COMMAND:
switch(LOWORD(wParam))
{
case ID_OK:
SendMessage(hWnd,WM_CLOSE,0,0);
return TRUE;
case ID_GETNAME:
GetWindowText(hIP,hostip,sizeof(hostip));
if(strlen(hostip)>0)
{
thGetName.Create((LPTHREAD_START_ROUTINE)GetHostNameThread,hostip,0);
}
return TRUE;
case ID_GETIP:
GetWindowText(hName,hostname,sizeof(hostname));
if(strlen(hostname)>0)
{
thGetIP.Create((LPTHREAD_START_ROUTINE)GetHostIPThread,hostname,0);
}
return TRUE;
case ID_WHOIS:
GetWindowText(hIP,hostip,sizeof(hostip));
if(strlen(hostip)>0)
thWhoIs.Create((LPTHREAD_START_ROUTINE)WhoIsThread,hostip,0);
return TRUE;
case ID_COPY:
CopyData(hWnd,hWhois);
return TRUE;
}
return FALSE;
case WM_CLOSE:
GetWindowText(hIP,hostip,sizeof(hostip));
GetWindowText(hName,hostname,sizeof(hostname));
GetWindowText(hWhois,whoisbuf,sizeof(whoisbuf));
hDialog=NULL;
hName=NULL;
hWhois=NULL;
DeleteObject(hfont);
thGetName.Terminate();
thGetName.Cleanup();
thGetIP.Terminate();
thGetIP.Cleanup();
thWhoIs.Terminate();
thWhoIs.Cleanup();
EndDialog(hWnd,TRUE);
if(MenuSet)
MenuSet((DWORD)MenuProc,MF_UNCHECKED);
return TRUE;
}
return FALSE;
}
//=========================================================================================
void SetList(HWND hList,USER *u,int iItem,int lParam)
{
LV_ITEM lvi;
char txt[32];
struct sockaddr_in sa;
lvi.mask=LVIF_TEXT|LVIF_PARAM|LVIF_IMAGE;
lvi.iSubItem=0;
lvi.iItem=iItem;
lvi.lParam=lParam;
switch(u->status)
{
case STATUS_NOT_AVAIL:
lvi.iImage=0;
break;
case STATUS_AVAIL:
lvi.iImage=1;
break;
case STATUS_BUSY:
lvi.iImage=2;
break;
case STATUS_INVISIBLE:
lvi.iImage=3;
break;
case STATUS_UNKNOWN:
lvi.iImage=4;
break;
default:
lvi.iImage=0;
}
lvi.pszText=u->nick;
ListView_InsertItem(hList,&lvi);
ListView_SetItemText(hList,lvi.iItem,1,itoa(u->uin,txt,10));
if(u->status==STATUS_UNKNOWN)
{
ListView_SetItemText(hList,iItem,2,"niewidoczny/niedostępny");
}
else if(u->status!=STATUS_NOT_AVAIL)
{
if(u->remote_port==0)
{
ListView_SetItemText(hList,iItem,2,"brak połączenia p2p");
}
else if(u->remote_port==1)
{
ListView_SetItemText(hList,iItem,2,"użytkownik za NATem");
}
else if(u->remote_port==2)
{
ListView_SetItemText(hList,iItem,2,"nie ma cię w kontaktach");
}
else
{
ListView_SetItemText(hList,iItem,2,"połączenie p2p");
}
/*
if(u->remote_port>2 || u->remote_port==1)
{
ListView_SetItemText(hList,i,3,inet_ntoa(sa.sin_addr));
if(u->remote_port!=1)
ListView_SetItemText(hList,i,4,itoa(u->remote_port,txt,10));
}
*/
if(u->remote_port>2)
ListView_SetItemText(hList,iItem,4,itoa(u->remote_port,txt,10));
//if(u->remote_port!=0)
if(u->protocol!=0)
ListView_SetItemText(hList,iItem,5,itoa(u->protocol,txt,10));
}
else
{
ListView_SetItemText(hList,iItem,2,"użytkownik niedostępny");
}
if(u->remote_ip)
{
memcpy(&(sa.sin_addr),&(u->remote_ip),4);
ListView_SetItemText(hList,iItem,3,inet_ntoa(sa.sin_addr));
}
if(*(u->time)!=0)
ListView_SetItemText(hList,iItem,6,u->time);
}
//=========================================================================================
BOOL CopyData(HWND hDialog,HWND hEdit)
{
HANDLE hMem;
char *szBuffer;
int iLines;
iLines = SendMessage(hEdit,EM_GETLINECOUNT,0,0);
if(!iLines)
return FALSE;
if(!OpenClipboard(hDialog))
return FALSE;
EmptyClipboard();
hMem=GlobalAlloc(GHND | GMEM_DDESHARE,65535);
szBuffer=(char *)GlobalLock(hMem);
*szBuffer='\0';
SendMessage(hEdit,WM_GETTEXT,65535,(LPARAM)szBuffer);
GlobalUnlock(hMem);
SetClipboardData(CF_TEXT,hMem);
CloseClipboard();
return TRUE;
}
//=========================================================================================
int CALLBACK SortList(LPARAM lParam1,LPARAM lParam2,LPARAM lParamSort)
{
unsigned int p1,p2;
char s1[32],s2[32],temp[32];
USER *u1,*u2;
int size;
size=userlist.Count();
if(lParam1<size)
u1=(USER *)userlist.Select(lParam1);
else
return 0;
if(lParam2<size)
u2=(USER *)userlist.Select(lParam2);
else
return 0;
switch(lParamSort)
{
case 0: // status
_set_satus:
if(u1->status<u2->status)
return -1;
else if(u1->status>u2->status)
return 1;
else
return strcmp_pl(u1->nick,u2->nick);
case 1: // numer GG
if(u1->uin<u2->uin) return -1;
else if(u1->uin>u2->uin) return 1;
else return 0;
case 2: // rodzaj polaczenia
p1=u1->remote_port;
p2=u2->remote_port;
if(p1<p2) return 1;
else if(p1>p2) return -1;
//else return 0;
goto _set_satus;
case 3: // ip
p1=u1->remote_ip;
p2=u2->remote_ip;
p1=(p1>>8*3)|((p1>>8)&0xff00)|((p1<<8)&0xff0000)|(p1<<8*3);
p2=(p2>>8*3)|((p2>>8)&0xff00)|((p2<<8)&0xff0000)|(p2<<8*3);
if(p1==0) p1--;
if(p2==0) p2--;
if(p1<p2) return -1;
else if(p1>p2) return 1;
//else return 0;
goto _set_satus;
case 4: // port
p1=u1->remote_port;
p2=u2->remote_port;
if(p1==0) p1--;
if(p2==0) p2--;
if(p1<p2) return -1;
else if(p1>p2) return 1;
//else return 0;
goto _set_satus;
case 5: // wersja
p1=u1->protocol;
p2=u2->protocol;
if(p1==0) p1--;
if(p2==0) p2--;
if(p1<p2) return -1;
else if(p1>p2) return 1;
//else return 0;
goto _set_satus;
case 6: // ostatnia zmiana
strcpy(temp,u1->time);
if(strlen(temp))
{
strcpy(s1,&temp[9]);
temp[8]=0;
strcat(s1,temp);
}
else
*s1=0;
strcpy(temp,u2->time);
if(strlen(temp))
{
strcpy(s2,&temp[9]);
temp[8]=0;
strcat(s2,temp);
}
else
*s2=0;
int res=stricmp(s2,s1);
if(res!=0) return res;
//else return 0;
goto _set_satus;
}
return 0;
}
//=========================================================================================
void GetHostNameThread(char *szIPAddr)
{
if(hDialog)
{
SetWindowText(hName,"");
EnableWindow(GetDlgItem(hDialog,ID_GETNAME),FALSE);
}
GetHostName(szIPAddr,hostname);
if(hName)
{
SetWindowText(hName,hostname);
}
if(hDialog)
EnableWindow(GetDlgItem(hDialog,ID_GETNAME),TRUE);
}
//=========================================================================================
void GetHostIPThread(char *szHostName)
{
if(hDialog)
{
SetWindowText(hIP,"");
EnableWindow(GetDlgItem(hDialog,ID_GETIP),FALSE);
}
GetHostIP(szHostName,hostip);
if(hIP)
{
SetWindowText(hIP,hostip);
}
if(hDialog)
EnableWindow(GetDlgItem(hDialog,ID_GETIP),TRUE);
}
//=========================================================================================
void WhoIsThread(char *szIPAddr)
{
char szHost[256];
if(hDialog)
{
SetWindowText(hWhois,"");
EnableWindow(GetDlgItem(hDialog,ID_WHOIS),FALSE);
}
strcpy(szHost,"whois.ripe.net");
WhoIs(szHost,szIPAddr,whoisbuf,sizeof(whoisbuf));
if(hWhois)
{
SetWindowText(hWhois,whoisbuf);
SetScrollPos(hWhois,SB_VERT,0,TRUE);
SendMessage(hWhois,WM_VSCROLL,(WPARAM)SB_THUMBPOSITION,0);
}
if(hDialog)
EnableWindow(GetDlgItem(hDialog,ID_WHOIS),TRUE);
}
//=========================================================================================
sorry że daje kod w c++ w dziale Delphi/Pascal ale tak to odczytuje inwigilator :) (wtyczka powergg w pliku DlgWnd.cpp)
najważniejsze zwrócić uwagę ten kawałek
```cpp
{
if(u->remote_port==0)
{
ListView_SetItemText(hList,iItem,2,"brak połączenia p2p");
}
else if(u->remote_port==1)
{
ListView_SetItemText(hList,iItem,2,"użytkownik za NATem");
}
else if(u->remote_port==2)
{
ListView_SetItemText(hList,iItem,2,"nie ma cię w kontaktach");
}
else
{
</b>