📄 connect.c
字号:
SelectPalette(hMemDC, mopal, FALSE);
DeleteObject(bpal);
}
DeleteDC(hMemDC);
pClientData->face_shown = TRUE;
}
GlobalFreePtr(savepal);
}
face_failed:
if (!pClientData->face_shown) {
int n = 0;
RECT cr;
HFONT ofont;
ofont = SelectObject(hdc, GetStockObject(ANSI_VAR_FONT));
SetBkColor(hdc, GetSysColor(COLOR_MENU));
SetTextColor(hdc, GetSysColor(COLOR_MENUTEXT));
WinPrintf(hdc, n, 1, pClientData->modemConnection ?
rstring(IDS_T_DIAL_STRING) : rstring(IDS_T_HOST));
WinPrintf(hdc, n++, DCOL, pClientData->szHost);
if (pClientData->modemConnection) {
WinPrintf(hdc, n, 1, rstring(IDS_T_MODEM_CONNECTION_L));
} else {
WinPrintf(hdc, n, 1, rstring(IDS_T_ADDRESS));
WinPrintf(hdc, n++, DCOL, Format(48),
inet_ntoa(pClientData->inetSock.sin_addr),
pClientData->port);
}
WinPrintf(hdc, n++, 1, pClientData->wantsInput ? rstring(IDS_T_TRANSMITTING) :
rstring(IDS_T_BLANKTRANSMIT));
WinPrintf(hdc, n, 1, Format(71));
WinPrintf(hdc, n++, DCOL, rstring(IDS_PROTOCOL_TYPES +
pClientData->protocol));
if ((pClientData->uname != NULL) &&
((pClientData->uname[0] & 0xFF) == 0xFF)) {
LPSTR sp, np;
int nl = 0;
WinPrintf(hdc, n, 1, Format(74));
sp = pClientData->uname + 1;
while (TRUE) {
np = _fstrstr(sp, ", ");
if (np != NULL) {
*np = 0;
}
WinPrintf(hdc, n++, DCOL, "%s", sp);
if (np != NULL) {
*np = ',';
sp = np + 2;
} else {
break;
}
nl++;
/* Too many in conference causes a crash I cannot reproduce
Limit to 8 names shown for now. */
if (nl >= 8) {
WinPrintf(hdc, n++, DCOL, "...");
break;
}
}
} else {
if ((pClientData->uname != NULL) && (pClientData->uname[0])) {
WinPrintf(hdc, n, 1, Format(69));
WinPrintf(hdc, n++, DCOL, "%s", pClientData->uname);
}
if (pClientData->email[0]) {
WinPrintf(hdc, n, 1, Format(70));
WinPrintf(hdc, n++, DCOL, "%s", pClientData->email);
}
}
#ifdef SHOW_STATE
/* It's nice to show the state, but costly to update on
every packet. */
WinPrintf(hdc, n, 1, "State:");
WinPrintf(hdc, n++, DCOL, "%s", stateToString(pClientData->state));
switch (pClientData->state) {
case Idle:
WinPrintf(hdc, n++, 1, blankit);
WinPrintf(hdc, n++, 1, blankit);
break;
case Transferring:
WinPrintf(hdc, n, 1, "File: ");
WinPrintf(hdc, n++, DCOL, "%s", pClientData->szFile);
WinPrintf(hdc, n, 1, "Bytes sent:");
WinPrintf(hdc, n++, DCOL, "%lu", pClientData->cbSent);
break;
case PlayingReceivedAudio:
WinPrintf(hdc, n, 1, "Bytes received:");
WinPrintf(hdc, n++, DCOL, "%lu", pClientData->cbReceived);
break;
}
#endif
SelectObject(hdc, ofont);
GetClientRect(hwnd, &cr);
if (cr.bottom != (n * tmHeight + 5)) {
RECT wr;
GetWindowRect(hwnd, &wr);
SetWindowPos(hwnd, HWND_TOP,
0, 0, wr.right - wr.left,
((wr.bottom - wr.top) - cr.bottom) +
(n * tmHeight + 5), SWP_NOMOVE | SWP_NOZORDER);
resized = TRUE;
//OutputDebugString("Resized connection window.\r\n");
}
}
#undef DCOL
}
EndPaint(hwnd, &psPaint);
if (resized) {
/* Oops--we resized the window after finishing the paint.
Now we have to invalidate it again so it will be
repainted in the new size. */
InvalidateRect(hwnd, NULL, TRUE);
UpdateWindow(hwnd);
}
}
break;
case WM_MDIACTIVATE:
if (wParam == FALSE || IsIconic(hwnd)) {
break;
}
if (pClientData != NULL && pClientData->face_shown) {
HDC hdc;
BITMAPINFOHEADER FAR *bmi;
HPALETTE bpal = NULL, opal;
int i;
LPLOGPALETTE lp;
BITMAPINFO FAR *bh;
LPSTR lpalette;
#ifdef TRACE_FACE
{ char s[256];
wsprintf(s, "MDI activate %04X: %s\r\n", hwnd, pClientData->szHost);
OutputDebugString(s);
}
#endif
lpalette = GlobalAllocPtr(GPTR, sizeof(LOGPALETTE) +
sizeof(PALETTEENTRY) * 256);
if (lpalette != NULL) {
bmi = (BITMAPINFOHEADER FAR *) (pClientData->face_bmp + sizeof(BITMAPFILEHEADER));
bh = (BITMAPINFO FAR *) bmi;
lp = (LOGPALETTE FAR *) lpalette;
lp->palVersion = 0x0300;
lp->palNumEntries = (WORD) bmi->biClrUsed;
for (i = 0; i < ((int) bmi->biClrUsed); i++) {
lp->palPalEntry[i].peRed = bh->bmiColors[i].rgbRed;
lp->palPalEntry[i].peGreen = bh->bmiColors[i].rgbGreen;
lp->palPalEntry[i].peBlue = bh->bmiColors[i].rgbBlue;
lp->palPalEntry[i].peFlags = PC_NOCOLLAPSE;
}
bpal = CreatePalette(lp);
if (bpal != NULL) {
hdc = GetDC(hwnd);
opal = SelectPalette(hdc, bpal, FALSE);
i = RealizePalette(hdc);
SelectPalette(hdc, opal, FALSE);
DeleteObject(bpal);
ReleaseDC(hwnd, hdc);
if (i > 0) {
HWND oldwin;
InvalidateRect(hwnd, NULL, TRUE);
UpdateWindow(hwnd);
oldwin = (HWND) wParam;
if (oldwin != NULL) {
InvalidateRect(oldwin, NULL, TRUE);
UpdateWindow(oldwin);
}
}
return i;
}
GlobalFreePtr(lpalette);
}
}
break;
#ifdef ASYNC_OUTPUT
case WM_SOCKET_SELECT:
if (pClientData != NULL) {
pClientData->outputSocketBusy = FALSE;
}
#ifdef OVERLOAD
{ char s[80];
wsprintf(s, "WM_SOCKET_SELECT Event = %d, Error = %d\r\n",
WSAGETSELECTEVENT(lParam), WSAGETSELECTERROR(lParam));
OutputDebugString(s);
}
#endif
case WM_SOCKET_CONTROL:
return 0;
#endif
case WM_SOCKET_ASYNC:
if (pClientData != NULL) {
if (WSAGETASYNCERROR(lParam) == 0) {
LPHOSTENT host;
host = (LPHOSTENT) pClientData->hostBuffer;
SetWindowText(hwnd, pClientData->localLoopback ?
rstring(IDS_T_LOOPBACK) : host->h_name);
_fstrcpy(pClientData->szHost, host->h_name);
changeAudioState(hwnd, pClientData);
#ifdef SHOW_GET_HOST_NAME_ERROR
} else {
MsgBox(hwnd, MB_ICONSTOP | MB_OK, Format(27),
pClientData->szHost, WSAGETASYNCERROR(lParam),
SockerrToString(WSAGETASYNCERROR(lParam)));
#endif
}
}
pClientData->getNameTask = NULL;
break;
/* Send text chat message as an RTCP APP packet on the control
channel. This is available only if the user is sending in
Speak Freely protocol. */
case WM_CHAT_TEXT_SEND:
if (protocolSent == PROTOCOL_SPEAKFREE) {
char v[256];
LPSTR chat_text = (LPSTR) lParam;
int l, n = strlen(chat_text);
l = rtp_make_app(v, ssrc, TRUE, RTCP_APP_TEXT_CHAT, chat_text);
// Set Speak Freely protocol flag in packet
v[0] = (v[0] & 0x3F) | (1 << 6);
sendSessionCtrl(pClientData, v, l);
}
break;
case WM_TIMER:
{
DWORD startTicks = GetTickCount();
if (pClientData == NULL) {
break;
}
/* If there are no buffers pending, advance the timeout
counter. When it reaches TIMEOUT_CONNECTION, close the
connection. */
if (wParam == FRAME_TIMER_ID && !broadcasting && !bConferencing &&
pClientData->timeout >= 0 && outputPending == 0) {
if ((pClientData->timeout++) >= TIMEOUT_CONNECTION) {
FORWARD_WM_MDIDESTROY(hwndMDIClient, hwnd, SendMessage);
return 0;
}
if (pClientData->timeout == 5) {
if (!IsIconic(hwnd)) {
pClientData->cbReceived = 0;
pClientData->state = Idle;
if (pClientData->face_stat == -1) {
pClientData->face_stat = FSinit;
}
#ifdef SHOW_STATE
InvalidateRect(hwnd, NULL, TRUE);
UpdateWindow(hwnd);
#endif
}
}
}
/* If it's time to resend the session identity
packet, go do it. */
if (wParam == FRAME_TIMER_ID) {
if (--(pClientData->sendSDEStimer) <= 0) {
char *msg = NULL;
int msgl;
char pid;
pClientData->sendSDEStimer = TIMEOUT_RESEND_SDES;
switch (protocolSent) {
case PROTOCOL_RTP:
case PROTOCOL_SPEAKFREE:
msg = rtpsdes;
msgl = rtpsdesl;
break;
case PROTOCOL_VAT:
msg = vatid;
msgl = vatidl;
break;
}
if (msg != NULL) {
pid = msg[0];
if (protocolSent == PROTOCOL_SPEAKFREE) {
msg[0] = (msg[0] & 0x3F) | (1 << 6);
}
if (!((protocolSent == PROTOCOL_SPEAKFREE) && waProtNoHeartbeat)) {
sendSessionCtrl(pClientData, msg, msgl);
}
msg[0] = pid;
}
}
}
/* If a broadcast is underway and the site has requested
to unsubscribe, close the connection after a decent
interval has elapsed to avoid toggling due to multiple
packets. */
if (wParam == FRAME_TIMER_ID && broadcasting &&
pClientData->broadcastEnd &&
((GetTickCount() - pClientData->broadcastBeginTime) >
(BroadcastUnsubscribe * 1000L))) {
FORWARD_WM_MDIDESTROY(hwndMDIClient, hwnd, SendMessage);
return 0;
}
/* Here's a little bit of paranoia. What if the socket
blocks or otherwise gets stuck and we don't get the
WM_SOCKET_SELECT/FD_WRITE message like we're guaranteed
to (right, tell me another) in the Winsock specification.
Well, if the socket's marked as busy, why not call select()
on every timer tick just to see if it's gotten unstuck
without bothering to let us know. Since all we do is
clear the busy flag, this won't interfere with the
notification message even if it's on the way at the
time we arrive here. */
if (wParam == FRAME_TIMER_ID && pClientData->outputSocketBusy) {
fd_set fds;
struct timeval t;
t.tv_sec = t.tv_usec = 0;
FD_ZERO(&fds);
FD_SET(pClientData->sReply, &fds);
if (select(1, NULL, &fds, NULL, &t) > 0) {
pClientData->outputSocketBusy = FALSE;
#ifdef OVERLOAD
OutputDebugString("Timer cleared socket busy after select()\r\n");
#endif
}
}
/* If loopback packets are queued, we're not still
recording them, but we haven't yet started to play
them back (and aren't otherwise occupied with a sound file),
start the playback process. */
if (wParam == FRAME_TIMER_ID &&
(pClientData->localLoopback & LOOPBACK_ENABLED) &&
!(pClientData->localLoopback & LOOPBACK_PLAYING) &&
(pClientData->llhead != NULL) &&
(pClientData->hFile == HFILE_ERROR &&
pClientData->mmioHandle == NULL) &&
!pClientData->wantsInput) {
pClientData->localLoopback |= LOOPBACK_PLAYING;
SetTimer(hwnd, 2, (UINT) 1000, NULL);
}
/* Button up timer has expired. If we're still transmitting,
cease transmission. */
if (wParam == 8) {
KillTimer(hwnd, 8);
pClientData->buttonUpTimer = FALSE;
if (pClientData->wantsInput) {
SendMessage(hwnd, WM_CHAR, ' ', 0L);
}
}
/* Cadence timer indicating it's time to send the
next block of a sound file. Read it in and send
it on its way. */
if (wParam == 2 && (pClientData->hFile != HFILE_ERROR ||
pClientData->mmioHandle != NULL ||
pClientData->localLoopback & LOOPBACK_PLAYING)) {
long et;
UINT bread = 0;
#ifdef MODEM
if (pClientData->modemConnection) {
int err;
COMSTAT cs;
err = GetCommError(modemHandle, &cs);
if (cs.cbOutQue > 1000) {
/* If modem connection and modem's backed up
with output, spin until it goes idle. */
SetTimer(hwnd, 2, 10, NULL);
break;
}
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -