📄 connect.c
字号:
switch (voxmode) {
case IDM_VOX_FAST:
voxSampleCountdown = 4000;
break;
case IDM_VOX_MEDIUM:
voxSampleCountdown = 8000;
break;
case IDM_VOX_SLOW:
voxSampleCountdown = 12000;
break;
}
}
}
if (compression) {
compress2X(&sb);
}
if (gsmcompress) {
gsmcomp(&sb);
}
if (adpcmcompress) {
// Sledgehammer to verify that lockup-prevention code works OK
//long l; l = GetTickCount();
//while (GetTickCount() - l < 350) ;
adpcmcomp(&sb);
}
if (lpccompress) {
lpccomp(&sb);
}
if (lpc10compress) {
lpc10comp(&sb);
}
pktlen = sb.buffer.buffer_len + (sizeof(struct soundbuf) - BUFL);
// Ugly, ugly ugly. RTP and VAT need compression modes here.
sb.compression = fProtocol;
sb.compression |= gsmcompress ? fCompGSM : 0;
sb.compression |= adpcmcompress ? fCompADPCM : 0;
sb.compression |= lpccompress ? fCompLPC : 0;
if (protocolSent == PROTOCOL_RTP) {
pktlen = rtpout(&sb, ssrc, timestamp, seq, spurt);
seq++;
timestamp += currentInputSamples;
} else if (protocolSent == PROTOCOL_VAT) {
pktlen = vatout(&sb, 0L, timestamp, spurt);
timestamp += currentInputSamples;
}
spurt = FALSE; /* Not the start of a talk spurt */
}
}
/* CREATENEWCONNECTION -- Create a new connection MDI window. */
HWND createNewConnection(LPCLIENT_DATA pClientData)
{
MDICREATESTRUCT mcs;
HWND hwnd;
SOCKERR serr = 0;
int vover;
#ifdef TRACE_FACE
OutputDebugString("createNewConnection()\r\n");
#endif
vover = (GetSystemMetrics(SM_CYFRAME) * 2) + GetSystemMetrics(SM_CYCAPTION) - 1;
mcs.szClass = pszClientClass;
mcs.szTitle = pClientData->localLoopback ?
rstring(IDS_T_LOOPBACK) : pClientData->szHost,
mcs.hOwner = hInst;
mcs.x = CW_USEDEFAULT;
mcs.y = CW_USEDEFAULT;
mcs.cx = tmAveCharWidth * 35;
mcs.cy = ((4 * tmHeight) + 5) + vover;
mcs.style = 0;
hwnd = FORWARD_WM_MDICREATE(hwndMDIClient, (LPMDICREATESTRUCT) &mcs, SendMessage);
if (hwnd == NULL) {
return NULL;
}
pClientData->state = Idle;
SetWindowLong(hwnd, GWL_CLIENT, (LONG) pClientData);
if (!pClientData->modemConnection) {
serr = CreateSocket(&(pClientData->sReply), SOCK_DGRAM,
htonl(INADDR_ANY), 0);
if (serr == 0) {
#ifdef ASYNC_OUTPUT
if (WSAAsyncSelect(pClientData->sReply, hwnd, WM_SOCKET_SELECT, FD_WRITE) != 0) {
serr = WSAGetLastError();
}
#endif
if (serr == 0) {
pClientData->name.sin_family = PF_INET;
pClientData->name.sin_addr = pClientData->inetSock.sin_addr;
pClientData->name.sin_port = htons(pClientData->port);
if (!waNetNoConnect) {
if (connect(pClientData->sReply, (LPSOCKADDR) &(pClientData->name),
sizeof(pClientData->name)) != 0) {
serr = WSAGetLastError();
}
}
}
}
if (serr != 0) {
MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(23),
(LPSTR) pClientData->szHost, serr, SockerrToString(serr));
return NULL;
}
// Create control socket for RTP and VAT protocol connections
serr = CreateSocket(&(pClientData->sControl), SOCK_DGRAM,
htonl(INADDR_ANY), 0);
if (serr == 0) {
#ifdef ASYNC_OUTPUT
if (WSAAsyncSelect(pClientData->sReply, hwnd, WM_SOCKET_CONTROL, FD_WRITE) != 0) {
serr = WSAGetLastError();
}
#endif
if (serr == 0) {
pClientData->ctrl.sin_family = PF_INET;
pClientData->ctrl.sin_addr = pClientData->inetSock.sin_addr;
pClientData->ctrl.sin_port = htons((short) (pClientData->port + 1));
if (!waNetNoConnect) {
if (connect(pClientData->sControl, (LPSOCKADDR) &(pClientData->ctrl),
sizeof(pClientData->ctrl)) != 0) {
serr = WSAGetLastError();
}
}
}
}
if (serr != 0) {
MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(67),
(LPSTR) pClientData->szHost, serr, SockerrToString(serr));
return NULL;
}
/* If this is a nonstandard port, create auxiliary sockets to
receive input from that port. */
if (pClientData->port != NETFONE_COMMAND_PORT) {
pClientData->auxSock = monitorPort(pClientData->port);
}
}
pClientData->gsmh = gsm_create();
pClientData->rseq = -1; // Initialise receive sequence number
rate_start(&pClientData->rateconv, 4000, 8000); // Initialise 2X decompression
/* Save the sending host for Speak Freely protocol packets. */
{
char gh[MAX_HOST];
gethostname(gh, sizeof gh);
if (strlen(gh) > ((sizeof ourSendingHost) - 1)) {
gh[(sizeof ourSendingHost) - 1] = 0;
}
strcpy(ourSendingHost, gh);
strcpy(sb.sendinghost, ourSendingHost);
}
#ifdef MODEM
if (pClientData->modemConnection) {
SetWindowText(hwnd, rstring(IDS_T_MODEM_CONNECTION));
modemSessions++;
} else
#endif
if (pClientData->szHost[0] == '(' && !pClientData->localLoopback) {
/* I'm sure by now you're shocked and stunned to discover that
some Winsock implementations, Sun PC-NFS 5.1, to name one,
don't correctly implement the WSAAsyncGetHostByAddr function.
Oh, you can make the call, and you even get back a valid host
name. But doing so plants a time bomb which will kill you
(at least under the debug kernel) much, much later when you call
WSACleanup() right before exiting the program. At that time,
depending on where the random pointer inside their so-called
WSHELPER points, you get either two invalid global pointer
errors or a fatal error due to an object usage count underflow in the
(bogus) global block. If the waNetSynchronousGetHostnameAction is
set, we eschew the asynchronous request and make the user
wait for a blocking gethostbyaddr() which has the merit, at
least, of not blowing us away at program termination time. */
if (!waNetSynchronousGetHostnameAction) {
/* This is a temporary connection initiated from the remote site.
Schedule a lookup to obtain the full domain name of the host,
not just the hostname included in the sound packet. */
pClientData->getNameTask = WSAAsyncGetHostByAddr(hwnd, WM_SOCKET_ASYNC,
(CHAR FAR *) &pClientData->inetSock.sin_addr,
sizeof(pClientData->inetSock.sin_addr),
PF_INET, pClientData->hostBuffer,
sizeof(pClientData->hostBuffer));
if (pClientData->getNameTask == NULL) {
int serr = WSAGetLastError();
MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(24),
(LPSTR) pClientData->szHost, serr, SockerrToString(serr));
}
} else{
LPHOSTENT h = gethostbyaddr((CHAR FAR *) &pClientData->inetSock.sin_addr,
sizeof(pClientData->inetSock.sin_addr),
PF_INET);
if (h == NULL) {
#ifdef SHOW_GET_HOST_NAME_ERROR
int serr = WSAGetLastError();
MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(27),
pClientData->szHost, serr,
SockerrToString(serr));
#endif
} else {
_fstrcpy(pClientData->szHost, h->h_name);
SetWindowText(hwnd, pClientData->localLoopback ?
rstring(IDS_T_LOOPBACK) : pClientData->szHost);
changeAudioState(hwnd, pClientData);
}
pClientData->getNameTask = NULL;
}
}
DragAcceptFiles(hwnd, TRUE);
ShowWindow(hwnd, SW_SHOW);
openConnections++;
propUpdateAudio();
return hwnd;
}
// CONNFETCHFACE -- Begin retrieval of a face image.
void connFetchFace(HWND hwndClient, LPCLIENT_DATA pClientData)
{
// pClientData->face_stat = FSabandoned;
// if (pClientData->face_stat != -1) {
#ifdef TRACE_FACE
OutputDebugString("connFetchFace()\r\n");
#endif
pClientData->face_address = 0L;
pClientData->face_timeout = 0;
pClientData->face_retry = 0;
pClientData->face_stat = FSreply; // Activate request from timeout
SetTimer(hwndClient, 5, (UINT) FaceFetchInterval, NULL);
// }
}
// STARTSOUNDFILE -- Begin playing a sound file.
VOID startSoundFile(HWND hwnd, LPSTR pszFile)
{
LPCLIENT_DATA pClientData;
HFILE hFile = HFILE_ERROR;
char magic[4];
pClientData = CLIENTPTR(hwnd);
pClientData->quitSoundFile = FALSE;
pClientData->hFile = HFILE_ERROR;
if (pClientData->timeout > 0) {
pClientData->timeout = 0;
}
pClientData->cbSent = 0L;
// Try to open it
hFile = _lopen(pszFile, OF_READ | OF_SHARE_DENY_WRITE);
if (hFile == HFILE_ERROR) {
// Error opening file
MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(25),
pszFile, (LPSTR) pClientData->szHost);
goto FatalError;
}
_lread(hFile, magic, sizeof(long));
/* See if it's a chunky, wavy RIFF. If so, delegate
handling of the file to the multimedia I/O package. */
if (memcmp(magic, "RIFF", 4) == 0) {
_lclose(hFile);
if (!readWaveInit(hwnd, pClientData, pszFile)) {
return;
}
} else {
/* If the file has a Sun .au file header, skip it.
Note that we still blithely assume the file is
8-bit ISDN u-law encoded at 8000 samples per
second. */
if (memcmp(magic, ".snd", 4) == 0) {
long startpos;
_lread(hFile, &startpos, sizeof(long));
revlong(&startpos);
_llseek(hFile, startpos, 0);
} else {
_llseek(hFile, 0L, 0);
}
pClientData->hFile = hFile;
}
pClientData->state = Transferring;
spurt = TRUE; // Consider sound file a "talk spurt"
if (pClientData->timeout > 0) {
pClientData->timeout = 0;
}
#ifdef SHOW_STATE
InvalidateRect(hwnd, NULL, TRUE);
UpdateWindow(hwnd);
#endif
DragAcceptFiles(hwnd, FALSE);
if (SetTimer(hwnd, 2, 200, NULL) == 0) {
MsgBox(NULL, MB_ICONSTOP | MB_OK, Format(26));
}
return;
FatalError:
if (hFile != HFILE_ERROR) {
_lclose(hFile);
}
}
/* FILEDROPPED -- Handle file dropped in connection window. */
static VOID fileDropped(HWND hwnd, HDROP hdrop)
{
LPCLIENT_DATA pClientData;
pClientData = CLIENTPTR(hwnd);
// Retrieve the dropped file
DragQueryFile(hdrop, 0, pClientData->szFile, sizeof(pClientData->szFile));
DragFinish(hdrop);
// Start output
startSoundFile(hwnd, pClientData->szFile);
}
/* STATETOSTRING -- Convert state value to string. */
static LPSTR stateToString(CLIENT_STATE state)
{
LPSTR pszResult;
switch (state) {
case Embryonic:
pszResult = rstring(IDS_T_INITIALISING);
break;
case Idle:
pszResult = rstring(IDS_T_IDLE);
break;
case SendingLiveAudio:
pszResult = rstring(IDS_T_SENDING_LIVE);
break;
case Transferring:
pszResult = rstring(IDS_T_SENDING_FILE);
break;
case PlayingReceivedAudio:
pszResult = rstring(IDS_T_PLAYING_AUDIO);
break;
default:
pszResult = rstring(IDS_T_UNKNOWN);
break;
}
return pszResult;
}
/* CONNECT_WNDPROC -- Connection main window procedure. */
LRESULT CALLBACK connectWndProc(HWND hwnd, UINT nMessage, WPARAM wParam, LPARAM lParam)
{
LPCLIENT_DATA pClientData;
pClientData = CLIENTPTR(hwnd);
switch (nMessage) {
// case WM_MDIACTIVATE:
// if (wParam) {
// InvalidateRect(hwnd, NULL, FALSE);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -