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

📄 micqcomponents.cpp

📁 聊天程序
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// MICQComponents.cpp: implementation of the CMICQComponents class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MIcqWin32x.h"
#include "MICQComponents.h"

#include "RecvDlgThread.h"
#include "RecvMsgDlg.h"
#include "RcvURLDlg.h"
#include "LoginDlg.h"
#include "ReqAuthDlg.h"

#include "UsrFoundDlg.h"

//#include "datatype.h"
#include "micq.h"
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
//#include <winsock2.h>
#include <time.h>
#include <string.h>
#include <stdarg.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>

#include <io.h>
#define S_IRUSR		_S_IREAD
#define S_IWUSR		_S_IWRITE



#define ADD_COMMAND(a, b)     else if ( ! strcasecmp( tmp, a) ) { strncpy( b,strtok(NULL," \n\t"), 16 ); }
#define ADD_MESS(a, b)     else if ( ! strcasecmp( tmp, a) ) { strncpy( b,strtok(NULL,"\n"), 450 ); }
#define ADD_COLOR(a)      else if ( ! strncmp( str2, a , strlen( a ) ) { if ( Color ) printf( a ); str2 += strlen( a );}


static char rcfile[256];

static char* contactsFound [100];
static int numContactsFound=0;
static DWORD uinsFound [100];

typedef struct 
{
   const char *name;
   WORD code;
} COUNTRY_CODE;

static COUNTRY_CODE Country_Codes[] = { {"USA",1 },
                                 {"Russia",7 },
                                 {"Australia",61 },
                                 {"Denmark",45 },
                                 {"Sweden",46 },
                                 {"Norway",47 },
                                 {"Canada",107 },
                                 {"Brazil",55 },
                                 {"UK",0x2c },
                                 {"Finland", 358 },
                                 {"Iceland", 354 },
                                 {"Algeria", 213 },
                                 {"American Samoa", 684 },
                                 {"Argentina", 54 },
                                 {"Aruba", 297 },
                                 {"Austria", 43 },
                                 {"Bahrain", 973 },
                                 {"Bangladesh", 880 },
                                 {"Belgium", 32 },
                                 {"Belize", 501 },
                                 {"Bolivia", 591 },
                                 {"Cameroon", 237 },
                                 {"Chile", 56 },
                                 {"China", 86 },
                                 {"Columbia", 57 },
                                 {"Costa Rice", 506 },
                                 {"Croatia", 385 }, /* Observerd */
                                 {"Cyprus", 357 },
                                 {"Czech Republic", 42 },
                                 {"Ecuador", 593 },
                                 {"Egypt", 20 },
                                 {"El Salvador", 503 },
                                 {"Ethiopia", 251 },
                                 {"Fiji", 679 },
                                 {"France", 33 },
                                 {"French Antilles", 596 },
                                 {"French Polynesia", 689 },
                                 {"Gabon", 241 },
                                 {"German", 49 },
                                 {"Ghana", 233 },
                                 {"Greece", 30 },
                                 {"Guadeloupe", 590 },
                                 {"Guam", 671 },
                                 {"Guantanomo Bay", 53 },
                                 {"Guatemala", 502 },
                                 {"Guyana", 592 },
                                 {"Haiti", 509 },
                                 {"Honduras", 504 },
                                 {"Hong Kong", 852 },
                                 {"Hungary", 36 },
                                 {"India", 91 },
                                 {"Indonesia", 62 },
                                 {"Iran", 98 },
                                 {"Iraq", 964 },
                                 {"Ireland", 353 },
                                 {"Israel", 972 },
                                 {"Italy", 39 },
                                 {"Ivory Coast", 225 },
                                 {"Japan", 81 },
                                 {"Jordan", 962 },
                                 {"Kenya", 254 },
                                 {"South Korea", 82 },
                                 {"Kuwait", 965 },
                                 {"Liberia", 231 },
                                 {"Libya", 218 },
                                 {"Liechtenstein", 41 },
                                 {"Luxembourg", 352 },
                                 {"Malawi", 265 },
                                 {"Malaysia", 60 },
                                 {"Mali", 223 },
                                 {"Malta", 356 },
                                 {"Mexico", 52 },
                                 {"Monaco", 33 },
                                 {"Morocco", 212 },
                                 {"Namibia", 264 },
                                 {"Nepal", 977 },
                                 {"Netherlands", 31 },
                                 {"Netherlands Antilles", 599 },
                                 {"New Caledonia", 687 },
                                 {"New Zealand", 64 },
                                 {"Nicaragua", 505 },
                                 {"Nigeria", 234 },
                                 {"Oman", 968 },
                                 {"Pakistan", 92 },
                                 {"Panama", 507 },
                                 {"Papua New Guinea", 675 },
                                 {"Paraguay", 595 },
                                 {"Peru", 51 },
                                 {"Philippines", 63 },
                                 {"Poland", 48 },
                                 {"Portugal", 351 },
                                 {"Qatar", 974 },
                                 {"Romania", 40 },
                                 {"Saipan", 670 },
                                 {"San Marino", 39 },
                                 {"Saudia Arabia", 966 },
                                 {"Saipan", 670 },
                                 {"Senegal", 221},
                                 {"Singapore", 65 },
                                 {"Slovakia", 42 },
                                 {"South Africa", 27 },
                                 {"Spain", 34 },
                                 {"Sri Lanka", 94 },
                                 {"Suriname", 597 },
                                 {"Switzerland", 41 },
                                 {"Taiwan", 886 },
                                 {"Tanzania", 255 },
                                 {"Thailand", 66 },
                                 {"Tunisia", 216 },
                                 {"Turkey", 90 },
                                 {"United Arab Emirates", 971 },
                                 {"Uruguay", 598 },
                                 {"Vatican City", 39 },
                                 {"Venezuela", 58 },
                                 {"Vietnam", 84 },
                                 {"Yemen", 967 },
                                 {"Yugoslavia", 38 },
                                 {"Zaire", 243 },
                                 {"Zimbabwe", 263 },
								 {"Not entered",0xffff } };


#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMICQComponents::CMICQComponents()
{

}

CMICQComponents::~CMICQComponents()
{

}

//Beginning of MICQ Code

/*********************************
This must be called every 2 min.
so the server knows we're still alive.
JAVA client sends two different commands
so we do also :)
**********************************/
void Keep_Alive( int sok )
{
   net_icq_pak pak;
   
   Word_2_Chars( pak.head.ver, ICQ_VER );
   Word_2_Chars( pak.head.cmd, CMD_KEEP_ALIVE );
   Word_2_Chars( pak.head.seq, seq_num++ );
   DW_2_Chars( pak.head.UIN, UIN );
   
   last_cmd[(seq_num - 1) & 0x3ff ] = Chars_2_Word( pak.head.cmd );
   SOCKWRITE( sok, &(pak.head.ver), sizeof( pak.head ) - 2 );

   Word_2_Chars( pak.head.ver, ICQ_VER );
   Word_2_Chars( pak.head.cmd, CMD_KEEP_ALIVE2 );
   Word_2_Chars( pak.head.seq, seq_num++ );
   DW_2_Chars( pak.head.UIN, UIN );
   
   last_cmd[(seq_num - 1) & 0x3ff ] = Chars_2_Word( pak.head.cmd );
   SOCKWRITE( sok, &(pak.head.ver), sizeof( pak.head ) - 2 );
   if ( Verbose )
   {
   AfxMessageBox("Send Keep_Alive packet to the server" );
   }
}

void Recv_Message( int sok, BYTE * pak )
{
   RECV_MESSAGE_PTR r_mesg;
CString Message;

//   M_print( "\n" );
   r_mesg = ( RECV_MESSAGE_PTR )pak;
   last_recv_uin = Chars_2_DW( r_mesg->uin );
   Print_UIN_Name( Chars_2_DW( r_mesg->uin ) );
/*   M_print( ":\a\nDate %d/%d/%d\t%d:%02d GMT\n", r_mesg->month, r_mesg->day, 
            Chars_2_Word( r_mesg->year ), r_mesg->hour ,  r_mesg->minute );
            
   M_print( "Type : %d \t Len : %d\n", Chars_2_Word( r_mesg->type ),
       Chars_2_Word( r_mesg->len ) );
*/   Do_Msg( sok, Chars_2_Word( r_mesg->type ), Chars_2_Word( r_mesg->len ), (char *)( r_mesg->len + 2 ), last_recv_uin ); 

/*   M_print( MESSCOL "%s\n" NOCOL, ((char *) &r_mesg->len) + 2 );*/
/*   ack_srv( sok, Chars_2_Word( pak.head.seq ) ); */
   /*Message.Format(":\a\nDate %d/%d/%d\t%d:%02d GMT\nType : %d \t Len : %d\n", r_mesg->month, r_mesg->day, 
            Chars_2_Word( r_mesg->year ), r_mesg->hour ,  r_mesg->minute , Chars_2_Word( r_mesg->type ),
       Chars_2_Word( r_mesg->len ) );
   AfxMessageBox(Message);*/
}

/*********************************
This must be called to remove messages
from the server
**********************************/
void snd_got_messages( int sok )
{
   net_icq_pak pak;
   
   Word_2_Chars( pak.head.ver, ICQ_VER );
   Word_2_Chars( pak.head.cmd, CMD_ACK_MESSAGES );
   Word_2_Chars( pak.head.seq, seq_num++ );
   DW_2_Chars( pak.head.UIN, UIN );
   
   last_cmd[ (seq_num - 1) & 0x3ff ] = Chars_2_Word( pak.head.cmd );
   SOCKWRITE( sok, &(pak.head.ver), sizeof( pak.head ) - 2 );
}

/*************************************
this sends over the contact list
**************************************/
void snd_contact_list( int sok )
{
   net_icq_pak pak;
   int num_used;
   int i, size;
   char *tmp;
   
   Word_2_Chars( pak.head.ver, ICQ_VER );
   Word_2_Chars( pak.head.cmd, CMD_CONT_LIST );
   Word_2_Chars( pak.head.seq, seq_num++ );
   DW_2_Chars( pak.head.UIN, UIN );
   
   tmp = (char *)pak.data;
   tmp++;
   for ( i=0, num_used=0; i < Num_Contacts ; i++ )
   {
      if ( (S_DWORD) Contacts[ i ].uin >  0 )
      {
         DW_2_Chars( (unsigned char *)tmp, Contacts[i].uin );
         tmp+=4;
         num_used++;
      }
   }
   pak.data[0] = num_used;
/*   Word_2_Chars( pak.data, num_used ); */
   size = ( ( int ) tmp - ( int ) pak.data );
   size += sizeof( pak.head ) - 2;
   last_cmd[seq_num - 1 ] = Chars_2_Word( pak.head.cmd );
   SOCKWRITE( sok, &(pak.head.ver), size );
}

/*************************************
this sends over the Invisible list
that allows certain users to see you
if you're invisible.
**************************************/
void snd_invis_list( int sok )
{
   net_icq_pak pak;
   int num_used;
   int i, size;
   char *tmp;
   
   Word_2_Chars( pak.head.ver, ICQ_VER );
   Word_2_Chars( pak.head.cmd, CMD_INVIS_LIST );
   Word_2_Chars( pak.head.seq, seq_num++ );
   DW_2_Chars( pak.head.UIN, UIN );
   
   tmp = (char *)pak.data;
   tmp++;
   for ( i=0, num_used=0; i < Num_Contacts ; i++ )
   {
      if ( (S_DWORD) Contacts[ i ].uin >  0 )
      {
         if ( Contacts[i].invis_list )
         {
            DW_2_Chars( (unsigned char*)tmp, Contacts[i].uin );
            tmp+=4;
            num_used++;
         }
      }
   }
   if ( num_used != 0 )
   {
      pak.data[0] = num_used;
      size = ( ( int ) tmp - ( int ) pak.data );
      size += sizeof( pak.head ) - 2;
      last_cmd[seq_num - 1 ] = Chars_2_Word( pak.head.cmd );
      SOCKWRITE( sok, &(pak.head.ver), size );
   }
}

/*************************************
this sends over the Visible list
that allows certain users to see you
if you're invisible.
**************************************/
void snd_vis_list( int sok )
{
   net_icq_pak pak;
   int num_used;
   int i, size;
   char *tmp;
   
   Word_2_Chars( pak.head.ver, ICQ_VER );
   Word_2_Chars( pak.head.cmd, CMD_VIS_LIST );
   Word_2_Chars( pak.head.seq, seq_num++ );
   DW_2_Chars( pak.head.UIN, UIN );
   
   tmp = (char *)pak.data;
   tmp++;
   for ( i=0, num_used=0; i < Num_Contacts ; i++ )
   {
      if ( (S_DWORD) Contacts[ i ].uin >  0 )
      {
         if ( Contacts[i].vis_list )
         {
            DW_2_Chars( (unsigned char*)tmp, Contacts[i].uin );
            tmp+=4;
            num_used++;
         }
      }
   }
   if ( num_used != 0 )
   {
      pak.data[0] = num_used;
      size = ( ( int ) tmp - ( int ) pak.data );
      size += sizeof( pak.head ) - 2;
      last_cmd[seq_num - 1 ] = Chars_2_Word( pak.head.cmd );
      SOCKWRITE( sok, &(pak.head.ver), size );
   }
}

/**************************************
This sends the second login command
this is necessary to finish logging in.
***************************************/
void snd_login_1( int sok )
{
   net_icq_pak pak;
   
   Word_2_Chars( pak.head.ver, ICQ_VER );
   Word_2_Chars( pak.head.cmd, CMD_LOGIN_1 );
   Word_2_Chars( pak.head.seq, seq_num++ );
   DW_2_Chars( pak.head.UIN, UIN );
   
   last_cmd[seq_num - 1 ] = Chars_2_Word( pak.head.cmd );
   SOCKWRITE( sok, &(pak.head.ver), sizeof( pak.head ) - 2 );
}

/************************************************
This is called when a user goes offline
*************************************************/
void User_Offline( int sok, BYTE * pak )
{
   int remote_uin;
   int index;

   remote_uin = Chars_2_DW( &pak[0] );

//   M_print( "\n" );
//   M_print( CONTACTCOL );
   index = Print_UIN_Name( remote_uin );
//   M_print( NOCOL );
//   M_print( " logged off.\t" );
//   Time_Stamp();
//   M_print( "\n" );

   log_event("User logged off","",remote_uin);
   if ( index != -1 )
   {
      Contacts[ index ].status = STATUS_OFFLINE;
      Contacts[ index ].last_time = time( NULL );
   }
}

void User_Online( int sok, BYTE * pak )
{

⌨️ 快捷键说明

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