⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 session.c

📁 NETBIOS C程序源代码 用于网络通信
💻 C
📖 第 1 页 / 共 2 页
字号:
	// BOOL Value Connect_Done is set when:
	//   --- Listen/Call Canceled
	//   --- Listen/Call TimeOuted
	//   --- Session Established
	//
	Connect_Done=TRUE;
	}
/*------------------------------------------------------------*/
BOOL  Cancel_Cmd(NCB far *CurNcb)
	{
	NCB  CancelNcb;

	memset(&CancelNcb,0,sizeof(NCB));
	CancelNcb.NCB_COMMAND=CANCEL;
	CancelNcb.NCB_BUFFER_PTR=(void far *)(CurNcb);
	NetBios(&CancelNcb);
	if(CancelNcb.NCB_CMD_CPLT==NB_SUCCESSFULLY_EXECUTED)
	    {
	    return(TRUE);
	    }
	else
	    {
	    return(FALSE);
	    }
	}
/*--------------------------------------------------------------*/
void  HangUp_Session(void)
	{
	char StatusStr[80]
	NCB  HangUp_Ncb;

	Get_Status_Bar(StatusStr);
	Set_Status_Bar("Closing Phone Process, Please Wait...");
	memset(&HangUp_Ncb,0,sizeof(NCB));
	HangUp_Ncb.NCB_COMMAND=HANG_UP_WAIT;
	HangUp_Ncb.NCB_LSN=PhoneSession;
	NetBios(&HangUp_Ncb);
	Set_Status_Bar(StatusStr);
	}
/*--------------------------------------------------------------*/
/*  High Level Function for Phoning, including                  */
/*  Receive Local Keys, Draw them on the screen,                */
/*  Receive Remote Keys, and Draw them on the screen too.       */
/*--------------------------------------------------------------*/
void  Phoning(void)
	{
	BOOL Done;
	BOOL Special;
	BYTE KeyVal;

	strcpy(OtherName,(char *)RemoteName);
	Refresh_Screen("Dailing Successfully! Now We Are Phoning...");
	Beep();
	
	Self_Sx=Self_Sy=0;
	Other_Sx=Other_Sy=0;

	Done=FALSE;
	Abort_Session=FALSE;
	Key_Buffer.Head=0;
	Key_Buffer.Tail=0;

	//
	//  SendOut Receive Key Command...
	//
	Hook_recvKey_Ncb();

	while(!Done)
	    {
	    if(kbhit)
		{
		Get_Key(&Special,&KeyVal);
		if(Special)
		    {
		    switch(KeyVal)
			{
			case CR:
			case LF:
			case TAB:
			case BACKSPACE:
			    Draw_key(TRUE,TRUE,KeyVal);
			    Send_Key(TRUE,KeyVal);
			    break;
			case KEY_F3:
			    Send_Key(TRUE,KEY_F3);
			    Done=TRUE;
			    break;			
			default:
			    Beep();
			}
		    }
		else
		    {
		    Draw_key(TRUE,FALSE,KeyVal);
		    Send_Key(FALSE,KeyVal); 
		    }
		}
	    if(Abort_Session)
		{
		Done=TRUE;
		}
	    else
		{
		while(Key_Buffer.Head!=Key_Buffer.Tail)
		    {
		    Special=Key_Buffer.KeyBlock[Key_Buffer.Tail].Phone_Cmd\
			    ==PHONE_CONTROL ? TRUE:;FALSE;	//Special Key?
		    KeyVal=Key_Buffer.KeyBlock[[Key_Buffer.Tail].Value;
		    disable();
		    Key_Buffer.Tail++;
		    Key_Buffer.Tail %=TYPE_AHEAD;
		    enable();

		    if(Special && KeyVal==KEY_F3)
			{
			Done=TRUE;
			}
	    	    else 
			{
			Draw_key(FALSE,Special,KeyVal);
			}
		    }
		}

	    Beep();
	    if(!Abort_Session)
		{
		HangUp_Session();
		Set_Status_Bar("Phoning Is Done. Press Any Key to Continue...");
		}
	    else
		{
		Set_Status_Bar("Remote Abort! Phoning Is Done. Press Any Key...");
		}
	    }
	getch();
	}
/*--------------------------------------------------------------*/
/*  Draw keys on Self_Area or Other_Area of the screen          */
/*--------------------------------------------------------------*/
void  Draw_Key(BOOL IsSelf,BOOL Special,BYTE KeyVal)
	{
	BOOL cnt;
	WORD Offset;

	if(IsSelf)			
	    {
	    if(!Special)		//Key Received From Own Keyboard.
		{
		Put_Char(SELF_SX+Self_Sx,SELF_SY+Self_Sy,\
		         KeyVal,SELFTEXT_FCOLOR,TEXT_BCOLOR);
		Self_Sx++;
		}
	    else
		{
		switch(KeyVal)
		    {
		    case CR:
		    case LF:
			Self_Sx=0;
			Self_Sy++;
			break;
		    case TAB:
			for(cnt=0;cnt<8;cnt++)
			    {
			    Draw_Key(IsSelf,FALSE,SPACE);
			    }
			break;
		    case BACKSPACE:
			if(Self_Sx<=0)
			    {
			    Beep();
			    }
			else
			    {
			    Self_Sx--;
			    Put_Char(SELF_SX+Self_Sx,SELF_SY+Self_Sy,\
		         	     SPACE,SELFTEXT_FCOLOR,TEXT_BCOLOR);
			    }
			break;
		    }
		}
	    if(Self_Sx>=SELF_WIDTH)
		{
		Self_Sx=0;
		Self_Sy++;
		}
	    if(Self_Sy>=SELF_HEIGHT)
		{
		Self_Sy--;
		for(cnt=1;cnt<SELF_HEIHGT;cnt++)
		    {
		    Offset=((SELF_SY+cnt)*80+(SELF_SX))*2;
		    movedata(VideoSeg,Offset,VideoSeg,Offset-160,SELF_WIDTH*2);
		    }
		Set_Color(SELF_SX+0,		SELF_SY+SELF_HEIGHT-1,\
			  SELF_SX+SELF_WIDTH-1,	SELF_SY+SELF_HEIGHT-1,\	
			  SELFTEXT_FCOLOR,TEXT_BCOLOR);
		}
	    gotoxy(SELF_SX+Self_Sx+1,SELF_SY+Self+Sy+1);
	    }
	else
	    {
	    if(!Special)		//Key Received From Remote User.
		{
		Put_Char(OTHER_SX+Other_Sx,OTHER_SY+Other_Sy,\
		         KeyVal,OTHERTEXT_FCOLOR,TEXT_BCOLOR);
		Other_Sx++;
		}
	    else
		{
		switch(KeyVal)
		    {
		    case CR:
		    case LF:
			Other_Sx=0;
			Other_Sy++;
			break;
		    case TAB:
			for(cnt=0;cnt<8;cnt++)
			    {
			    Draw_Key(IsSelf,FALSE,SPACE);
			    }
			break;
		    case BACKSPACE:
			if(Other_Sx<=0)
			    {
			    Beep();
			    }
			else
			    {
			    Other_Sx--;
			    Put_Char(OTHER_SX+Other_Sx,OTHER_SY+Other_Sy,\
		         	     SPACE,SELFTEXT_FCOLOR,TEXT_BCOLOR);
			    }
			break;
		    }
		}
	    if(Other_Sx>=OTHER_WIDTH)
		{
		Other_Sx=0;
		Other_Sy++;
		}
	    if(Other_Sy>=OTHER_HEIGHT)
		{
		Other_Sy--;
		for(cnt=1;cnt<OTHER_HEIHGT;cnt++)
		    {
		    Offset=((OTHER_SY+cnt)*80+(OTHER_SX))*2;
		    movedata(VideoSeg,Offset,VideoSeg,Offset-160,OTHER_WIDTH*2);
		    }
		Set_Color(OTHER_SX+0,			OTHER_SY+OTHER_HEIGHT-1,\
			  OTHER_SX+OTHER_WIDTH-1,	OTHER_SY+OTHER_HEIGHT-1,\	
			  OTHERTEXT_FCOLOR,TEXT_BCOLOR);
		}
	    }
	}
/*--------------------------------------------------------------*/
/*   Send Keys or Controling Command to the remote user         */
/*--------------------------------------------------------------*/
BOOL  Send_Key(BOOL Special,BYTE KeyVal)
	{
	PHONE_DATA_BLOCK KeyBlock;

	KeyBlock.Phone_Cmd=Special?PHONE_CONTROL:PHONE_KEYVAL;
	KeyBlock.Value=KeyVal;

	memset(&Send_Ncb,0,sizeof(NCB));
	Send_Ncb.NCB_COMMAND=SEND_WAIT;
	Send_Ncb.NCB_LSN=PhoneSession;
	Send_Ncb.NCB_BUFFER_PTR=(void far *)&KeyBlock;
	Send_Ncb.NCB_LENGTH=sizeof(PHONE_DATA_BLOCK);
	NetBios(&Send_Ncb);
	if(Send_Ncb.NCB_CMD_CPLT==NB_SUCCESSFULLY_EXECUTED)
	    {
	    return(TRUE);
	    }
	else
	    {
	    Abort_Session=TRUE
	    return(FALSE);
	    }
	}
/*--------------------------------------------------------------*/
/*   Receiving and Buffering Remote Keys                        */
/*--------------------------------------------------------------*/
void  interrupt Key_Received(void)
	{
	enable();
	switch(Recv_Ncb.NCB.CMD_CPLT)
	    {
	    case NB_SUCCESSFULLY_EXECUTED:
		if(Recv_Ncb.NCB_LENGTH==sizeof(PHONE_DATA_BLOCK))
		    {
		    if((Key_Buffer.Head+1) % TYPE_AHEAD !=Key_Buffer.Tail)
			{
			Key_Buffer.KeyBlock[Key_Buffer.Head].Phone_Cmd=\
				Key_Data_Block.Phone_Cmd;
			Key_Buffer.KeyBlock[Key_Buffer.Head].Value=\
				Key_Data_Block.Value;
			Key_Buffer.Head++;
			Key_Buffer.Head %=TYPE_AHEAD;
			}
		    else
			{
			Beep();
			}
		    }
		Hook_RecvKey_Ncb();
		break;
	    case NB_COMMAND_TIMED_OUT:
		Hook_RecvKey_Ncb();
		break;
	    default:
		Abort_Session=TRUE;
		break;
	    }
	}
/*--------------------------------------------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -