📄 awarenetdivers.cpp
字号:
//////////////////////////////////////////////////////////////////////
// FileFury
// Copyright (c) 2000 Tenebril Incorporated
// All rights reserved.
//
// This source code is governed by the Tenebril open source
// license (http://www.tenebril.com/developers/opensource/license.html)
//
// For more information on this and other open source applications,
// visit the Tenebril OpenSource page:
// http://www.tenebril.com/developers/opensource
//
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include <string.h>
#include <stdlib.h>
#include "AwareNetClass.h"
#include "AwareNetDivers.h"
int AwareNet_FindIP(CAwareNet *Net, CString email, CString &ip,
BOOL bForceLookup)
{
int i, id;
CPersonalInfo PInfo;
if(!Net)
return -1;
/* E-mail names in AwareNet are always lowercase. Make
the input string lowercase. Not great style- other
people may point to this string. */
email.MakeLower();
/* Check all the friends */
for(i = 0; (id = Net->GetFriend(i)) >= 0; i++)
{
/* Extract the profile information */
Net->GetProfile(id, PInfo);
/* Check to see if this is the person */
if(email.Compare(PInfo.GetEMail()) == 0)
{
/* Get the IP address */
CString cszIPBuffer;
BOOL bRet;
if(bForceLookup)
Net->IsOnline(id, AWARENET_OSCAR_TOS, true);
bRet = Net->GetIP(cszIPBuffer, id);
ip = cszIPBuffer;
if(bRet) return 1;
return 0;
}
}
// Don't care about acquaintances.
/*
// Same for acquaintances
for(i = 0; (id = Net->GetAcquaintance(i)) >= 0; i++)
{
// Extract the profile information
Net->GetProfile(id, PInfo);
// Check to see if this is the person
if(email.Compare(PInfo.GetEMail()) == 0)
{
// Get the IP address
TCHAR ipBuffer[AWARENET_MAX_IP];
bool bRet = Net->GetIP(id, ipBuffer, AWARENET_MAX_IP);
ip = ipBuffer;
if(bRet) return 1;
return 0;
}
}
*/
/* This person is not a friend or acquaintance; we don't
have his IP available to us */
return -2;
}
BOOL AwareNet_GetMyEmail(CAwareNet *Net, CString &email)
{
CPersonalInfo PInfo;
if(!Net)
return false;
if(!Net->GetMyProfile(PInfo))
return false;
email = CString(PInfo.GetEMail());
return true;
}
BOOL AwareNet_GetMyName(CAwareNet *Net, CString &name)
{
CPersonalInfo PInfo;
if(!Net)
return false;
if(!Net->GetMyProfile(PInfo))
return false;
name = CString(PInfo.GetName());
return true;
}
/* Used to pass parameters to the thread. You don't need to use
this structure yourself */
typedef struct {
CAwareNet *Net;
HWND Window;
int Service;
BOOL *AwareNetInitialized;
} StartAwareNetStruct;
static HANDLE handleThread;
/* This is the thread work function. It's static; you never need
to call or use it directly */
static UINT StartAwareNet_Thread(LPVOID *Param)
{
StartAwareNetStruct *Struct = (StartAwareNetStruct *)Param;
/* Check the parameters */
if(!Struct || !Struct->Net || !Struct->Window || !Struct->AwareNetInitialized)
{
handleThread = NULL;
return 1;
}
/* Start AwareNet, and return its success appropriately */
BOOL bInit = Struct->Net->Initialize(Struct->Window, Struct->Service);
/* For cleanliness, you might want to post a Windows message to let
your program know AwareNet has been initialized, or release a Mutex. */
// This is not safe.
/*
CWnd *pWnd = CWnd::FromHandle(Struct->Window);
ASSERT(pWnd);
pWnd->SetForegroundWindow();
*/
// Additionally, Oscar needs some anonymous acquaintances.
if(bInit)
Struct->Net->AddAnonAcquaintances(5, Struct->Service);
// Now tell the system it's initialized.
*(Struct->AwareNetInitialized) = bInit;
/* The structure was allocated for us; we need to free */
free((void *)Struct);
handleThread = NULL;
return 1;
}
void AwareNet_AsyncWait()
{
while(handleThread)
Sleep(1000); // One second.
}
void AwareNet_AsyncInitialize(CAwareNet *Net,
HWND WindowHandle,
int Service,
BOOL *Result)
{
CWinThread *Thread;
StartAwareNetStruct *Struct;
/* This will be freed by the thread when it's done */
Struct = (StartAwareNetStruct *)malloc(sizeof(StartAwareNetStruct));
/* Fill the structure to pass the parameters to the new thread */
Struct->Net = Net;
Struct->Window = WindowHandle;
Struct->Service = Service;
Struct->AwareNetInitialized = Result;
/* This won't get set to true until the Initialize function returns
successfully. You may want to mutex this */
*Result = false;
/* The Thread pointer here is not used. You may want to keep it
around for liveness checking */
Thread = AfxBeginThread((AFX_THREADPROC)(StartAwareNet_Thread),
(LPVOID)Struct, THREAD_PRIORITY_NORMAL);
ASSERT(Thread);
if(!Thread) return;
handleThread = Thread->m_hThread;
return;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -