1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651 |
- /********************************************************************/
- /* */
- /* CONNECTSOCKET.CPP */
- /* */
- /* Implementation of the Connect Socket. */
- /* This class is a part of the CConnectThread which handles */
- /* socket connections. Incomming data is processed in OnReceive */
- /* */
- /* Programmed by LYFZ van der Meer */
- /* Based partially on and inspired by FileZilla Server. */
- /* */
- /* http://www.LYFZvandermeer.nl */
- /* */
- /* Last updated: 15 july 2002 */
- /* */
- /********************************************************************/
- //在ConnectSocket.cpp文件中实现连接套接字的创建,该类是CConnectThread类的
- //一部分,收到数据由函数OnReceive()完成处理。 net_Send
- #include "stdafx.h"
- #include "LYFZReceiveMsgApp.h"
- #include "LYFZReceiveMsg.h"
- #include "ConnectSocket.h"
- #include "ConnectThread.h"
- #include "ApplicationDlg.h"
- #include "DataSocket.h"
- #include "mysqldata.h"
- #include "./include/netMain.h"
- #include "./include/protocolhdr.h"
- #include "./include/struct_def.h"
- #include "MyLock.h"
- extern CLYFZReceiveMsg theServer;
- extern BOOL EncryptFile2(BYTE *buffer, DWORD leng, PCHAR szPassword);
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern CLYFZReceiveMsg *g_pWndServer;
- CStringArray g_baduserarray;
- ////////////////////////////////////////insert into
- BOOL BadUser(CString account)
- {
- for(int i=0; i<g_baduserarray.GetSize (); i++)
- {
- if(account==g_baduserarray.ElementAt (i))return 1;
- }
- return 0;
- }
- //----------------------------------------------------------------------------------
- // Remark by Jeff;
- // 函数:CheckUser;
- // 描述:检查短信用户账号、密码;
- // 参数:
- // account: 短信账号;
- // psw: 短信账号密码;
- // name: 用户名?
- // phone: 接收短信的手机;
- // signname: 短信内容签名;
- // pDb: 连接的数据库;
- // nRoadType: 短信通道类型?
- //
- // 返回:
- // FALSE 表示账号和密码错误;
- // TRUE 表示账号和密码正确;
- //
- //
- //
- //----------------------------------------------------------------------------------
- BOOL CheckUser(CString account, CString psw, CString &name, CString &phone, CString &signname, CDatabase *pDb, int &nRoadType)
- {
- name="";
- phone="";
- signname="";
- nRoadType=0;
- CRstClientInfo rsSt;
- rsSt.m_pDatabase=pDb;
- rsSt.m_strFilter ="[account]='"+account+"' and [psw]='"+psw+"'";
- rsSt.Open();
- if(!rsSt.IsEOF())
- {
- name=rsSt.m_name;
- phone=rsSt.m_phone;
- nRoadType=atoi(rsSt.m_road);
- signname=rsSt.m_signname;
- rsSt.Close();
- return 1;
- }
- rsSt.Close();
- return 0;
- }
- //------------------------------------------------------------------------------
- // Remark by Jeff;
- // 函数:CheckPhoneType
- // 描述:判断手机号属于哪个运营商的;
- // 参数:
- // phoneno: 欲判断的手机号;
- //
- // 返回:返回0表示移动; 1表示联通; 2表示电信; 3表示小灵通; -1表示未知的;
- //
- // 注意:
- //
- //------------------------------------------------------------------------------
- int CheckPhoneType(CString phoneno)
- {
- int i = 0;
- if(phoneno.IsEmpty ())return -1;
- for( i=0; i<phoneno.GetLength (); i++)
- {
- if(phoneno.GetAt (i)<'0'||phoneno.GetAt (i)>'9')return -1;
- }
- if(phoneno.GetAt (0)=='1')
- {
- if(phoneno.GetLength ()!=11)
- return -1;
- int mobile[]={139,138,137,136,135,134,159,158,152,151,150,157,188,187,144,182,147,183,184,178};
- int unicom[]={130,131,132,155,156,186,185,176};
- int telecom[]={133,153,189,180,181,177};
- for(i=0; i<sizeof(mobile)/sizeof(int); i++)
- {
- if(mobile[i]==atoi(phoneno.Left (3)))
- {
- return 0;
- }
- }
- for(i=0; i<sizeof(unicom)/sizeof(int); i++)
- {
- if(unicom[i]==atoi(phoneno.Left (3)))
- {
- return 1;
- }
- }
- for(i=0; i<sizeof(telecom)/sizeof(int); i++)
- {
- if(telecom[i]==atoi(phoneno.Left (3)))
- {
- return 2;
- }
- }
- return -1;
- }
- /* else if(phoneno.GetAt (0)=='0')
- {
- if(phoneno.GetLength ()>=10 && phoneno.GetLength ()<=12)
- {
- return 3;
- }
- }*/
- return -1;
- }
- BOOL MyExecuteSQL(CDatabase *pdb, CString sql)
- {
- // MyLock lock("xiaoaccessdbmsg");
- try
- {
- pdb->ExecuteSQL (sql);
- }
- catch(CDBException * e)
- {
- WriteError(sql+"操作数据库失败"+e->m_strError);
- return 0;
- }
- return 1;
- }
- void ReCalAccount(CString account, CDatabase *pDb)
- {
- CString sql;
- if(1)
- {
- // MyLock lock("xiaoaccessdbmsg");
- CRecordset myset(pDb);
- CString count1,count2,count3;
- #ifdef SQLSERVER_VERSION
- sql="select sum(cast([count] as float)) as cot from recharge where account='"+account+"'";
- #else
- sql="select sum([count]) as cot from recharge where account='"+account+"'";
- #endif
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count1);
- myset.Close();
- #ifdef SQLSERVER_VERSION
- sql="select sum(cast([msgcount] as float)) as cot from sendreg where account='"+account+"'";
- #else
- sql="select sum([msgcount]) as cot from sendreg where account='"+account+"'";
- #endif
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count2);
- myset.Close();
- sql="select count(*) as cot from receivemsg where [account]='"+account+"' and [replyok]='1'";
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count3);
- myset.Close();
- // sql.Format ("update clientinfo set balance='%d' where account='%s'", atoi(count1)-min(atoi(count2),atoi(count3)), account);
- sql.Format ("update clientinfo set balance='%d' where account='%s'", (atoi(count1)-atoi(count2))-atoi(count3), account);
- }
- MyExecuteSQL(pDb, sql);
- }
- /*
- 移动:
- 139,138,137,136,135,134,159,158,152,151,150,157,188,187,144
- 联通:
- 130,131,132,155,156,186,185
- 电信:
- 133,153,189,180
- */
- extern void WriteLogin(CString str);
- //------------------------------------------------------------------------------------------
- // Remark by Jeff; 2014-09-21
- // 函数:GetBalance
- // 描述:通过Select Sum SQL语句,获取数据库指定条件值的总和;
- // 参数:
- // account: 短信账号;
- // pDB: 连接的数据库实例对象指针;
- //
- // 返回:查询失败返回-1;成功返回其他值;
- //
- // 注意:
- // 1.如果[sendreg].[msgcount]值不对的话,那么会造成很严重的后果,不仅返回给客户的值不对,扣费也错乱甚至造成亏本;
- //
- //
- //------------------------------------------------------------------------------------------
- int GetBalance(CString account, CDatabase *pDb)
- {
- CString count1=""; // 该账号充值的短信数量,[recharge]表; (应该不是剩余数量,这个充值的值应该是在下一次充值时才会改变)
- CString count2=""; // 短信发送成功的扣费总和,[sendreg]表;
- CString count3=""; // 短信接收成功的扣费总和,[receivemsg]表;
- try
- {
- CRecordset myset(pDb);
- #ifdef SQLSERVER_VERSION
- CString sql="select sum(cast([count] as float)) as cot from recharge where account='"+account+"'";
- #else
- CString sql="select sum([count]) as cot from recharge where account='"+account+"'";
- #endif
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count1);
- myset.Close();
- #ifdef SQLSERVER_VERSION
- sql="select sum(cast([msgcount] as float)) as cot from sendreg where account='"+account+"'";
- #else
- sql="select sum([msgcount]) as cot from sendreg where account='"+account+"'";
- #endif
- myset.Open(CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue("cot", count2);
- myset.Close();
- sql="select count(*) as cot from receivemsg where [account]='"+account+"' and [replyok]='1'";
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count3);
- myset.Close();
- return (atoi(count1)-atoi(count2))-atoi(count3);
- }
- catch(...)
- {
- return -1;
- }
- }
- int GetLengthEx(CString str) // Jeff:获取多字节对应的宽字符数;
- {
- #if 0 // Jeff delete;
- wchar_t wstr[500];
- int k = MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, str, strlen(str), wstr, 500);
- return k;
- #else
- return ::MultiByteToWideChar(CP_ACP,0,str,-1,NULL,0);// Jeff.无论constent是否空,MultiByteToWideChar返回结果都>=1;
- #endif
- }
- //------------------------------------------------------------------------------------------
- // Remark by Jeff; 2014-09-21
- // 函数:GetBalanceUsed
- // 描述:获取账号可用剩余短信数,并更新到数据库表记录中;
- // 参数:
- // account: 短信账号;
- // pDB: 连接的数据库实例对象指针;
- // ret1: 账号可用的剩余短信数量;
- // ret2: 账号已用的短信总数;
- //
- // 返回:查询失败返回-1;成功返回其他值;
- //
- //
- //------------------------------------------------------------------------------------------
- void GetBalanceUsed(CString account, int &ret1,int &ret2, CDatabase *pDb)
- {
- CString count1=""; // 该账号充值的短信数量,[recharge]表; (应该不是剩余数量,这个充值的值应该是在下一次充值时才会改变)
- CString count2=""; // 短信发送成功的扣费总和,[sendreg]表;
- CString count3=""; // 短信接收成功的扣费总和,[receivemsg]表;
- ret1=0;
- ret2=0;
- try
- {
- CRecordset myset(pDb);
- #ifdef SQLSERVER_VERSION
- CString sql="select sum(cast([count] as float)) as cot from recharge where account='"+account+"'";
- #else
- CString sql="select sum([count]) as cot from recharge where account='"+account+"'";
- #endif
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count1);
- myset.Close();
- #ifdef SQLSERVER_VERSION
- sql="select sum(cast([msgcount] as float)) as cot from sendreg where account='"+account+"'";
- #else
- sql="select sum([msgcount]) as cot from sendreg where account='"+account+"'";
- #endif
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count2);
- myset.Close();
- sql="select count(*) as cot from receivemsg where [account]='"+account+"' and [replyok]='1'";
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count3);
- myset.Close();
- ret2 = atoi(count2)+atoi(count3) ;
- ret1 = atoi(count1)-ret2;
- sql.Format ("update clientinfo set balance='%d' where account='%s'", ret1, account);
- MyExecuteSQL(pDb, sql);
- }
- catch(...)
- {
- }
- }
- //------------------------------------------------------------------------------------------
- // Remark by Jeff: 2014.09.21
- // 函数:GetCount
- // 描述:指定短信内容和手机号,计算出要发送的短信条数;
- // 参数:
- // phones: 以逗号分隔的手机号串;
- // content: 短信内容;
- //
- // 返回:短信条数;
- //
- // 注意:
- //
- //------------------------------------------------------------------------------------------
- int GetCount(CString phones, CString content)
- {
- #if 0 // Jeff delete;
- int count=0;
- int leng=GetLengthEx(content);
- int m_nMobile=0; // Jeff:移动联通电信手机数;
- int m_nPhone=0; // Jeff:小灵通手机数;
- CStringArray phonearray;
- int pos=phones.Find (",");
- if(pos!=-1)
- {
- phonearray.Add(phones.Left (pos));
- phones=phones.Right (phones.GetLength ()-pos-1);
- pos=phones.Find (",");
- while(pos!=-1)
- {
- phonearray.Add (phones.Left (pos));
- phones=phones.Right (phones.GetLength ()-pos-1);
- pos=phones.Find (",");
- }
- phonearray.Add (phones);
- }
- else
- phonearray.Add (phones);
- for(int i=0; i<phonearray.GetSize (); i++)
- {
- phones=phonearray.ElementAt (i);
- if(CheckPhoneType(phones)==0 || CheckPhoneType(phones)==1 || CheckPhoneType(phones)==2)
- m_nMobile++;
- else if(CheckPhoneType(phones)==3)
- m_nPhone++;
- }
- // Jeff:小灵通和以外的手机短信字符长度有差别;
- if(m_nMobile)
- {
- count+=m_nMobile*(leng/70);
- if(leng%70)
- count+=m_nMobile;
- }
- if(m_nPhone)
- {
- count+=m_nPhone*(leng/56);
- if(leng%56)
- count+=m_nPhone;
- }
- return count;
- #else
- // 1.首先分析出短信内容会被拆分成多少条短信发送;
- int nNumberOfTextMsg = 0; // 短信条数;
- int nWCharLen = ::MultiByteToWideChar(CP_ACP,0,content,-1,NULL,0); // Jeff.无论constent是否空,MultiByteToWideChar返回结果都>=1;
- // 魔数MSG_LENGTH = 67:
- // 当短信字符数超过70时,短信服务商会分为两部分;
- // 1.将前67个字符为一条短信;
- // 2.将67后的为另一部分,若仍大于70,再次执行1;
- // 3.若短信小于等于70,则为一条短信;
- nNumberOfTextMsg = nWCharLen / 67;
- if (nWCharLen % 67 > 2 ) ++nNumberOfTextMsg;
- //if (nWCharLen % 67 ) ++nNumberOfTextMsg; // 如果 nWCharLen%67 不大于2,会多扣客户一条短信费用;
- // 2.其次解析手机字符串,获取手机数量;(不考虑小灵通,通用使用67字符截断短信)
- int nCountOfMobile = 0;
- int nIndex = 0;
- do
- {
- nIndex = phones.Find(",");
- if (nIndex != -1)
- {
- if ( nIndex == 11 && CheckPhoneType(phones.Left(nIndex)) != -1) // Jeff,CheckPhoneType返回-1表示未知手机类型;
- ++nCountOfMobile;
-
- phones = phones.Mid(nIndex+1);
- }
- else
- {
- if ( phones.GetLength() == 11 && CheckPhoneType(phones) != -1)
- ++nCountOfMobile;
- }
- } while (nIndex != -1);
- return nNumberOfTextMsg *= nCountOfMobile;
- #endif
- }
- //---------------------------------------------------------------------------------------------
- // Remark by Jeff;
- // 函数:IsExist
- // 描述:查询指定的短信账号要发送的【目标内容+手机+时间戳】是否存在;
- // 参数:
- // account: 短信账号;
- // phones: 接收短信的手机串;
- // content: 短信内容;
- // timestamp: 发送时间;
- // pDb: 连接数据库的对象指针;
- //
- // 返回:存在返回TRUE;
- //
- //---------------------------------------------------------------------------------------------
- BOOL IsExist(CString account, CString phones, CString content, CString timestamp, CDatabase *pDb)
- {
- //已保存此条记录, 不再保存, 否则重复
- // MyLock lock("xiaoaccessdbmsg");
- CRecordset myset(pDb);
- CString sql="select count(*) as cot from sendreg where [account]='"+account+"' and [content]='"+content+"' and [phones]='"+phones+"' and [timestamp]='"+timestamp+"'";
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- {
- myset.GetFieldValue ("cot", sql);
- if(atoi(sql))
- return 1;
- else
- return 0;
- }
- else
- return 0;
- }
- void WriteLog(CString account, CString str)
- {
- }
- /********************************************************************/
- /* */
- /* Function name : CConnectSocket::CConnectSocket */
- /* Description : Constructor */
- /* */
- /********************************************************************/
- CConnectSocket::CConnectSocket()
- {
- m_bLoggedon = FALSE;
- m_bRenameFile = FALSE;
- m_pDataSocket = NULL;
- m_nRemotePort = -1;
- m_dwRestartOffset = 0;
- m_bPassiveMode = FALSE;
- m_reved=0;
- m_dateleng=0;
- m_pRevBuf=NULL;
- }
- /********************************************************************/
- /* */
- /* Function name : CConnectSocket::~CConnectSocket */
- /* Description : Destructor */
- /* */
- /********************************************************************/
- CConnectSocket::~CConnectSocket()
- {
- DestroyDataConnection();
- // tell our thread we have been closed
- AfxGetThread()->PostThreadMessage(WM_QUIT,0,0);
- TRACE0("CConnectSocket destroyed.\n");
- if(m_pRevBuf)delete []m_pRevBuf;
- }
- // Do not edit the following lines, which are needed by ClassWizard.
- #if 0
- BEGIN_MESSAGE_MAP(CConnectSocket, CSocket)
- //{{AFX_MSG_MAP(CConnectSocket)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- #endif // 0
- /********************************************************************/
- /* */
- /* Function name : OnClose */
- /* Description : Send WM_QUIT message to the thread containing */
- /* the socket to shutdown once the connection is */
- /* closed. */
- /* */
- /********************************************************************/
- void CConnectSocket::OnClose(int nErrorCode)
- {
- try
- {
- Close();
- // destroy connection
- m_pThread->PostThreadMessage(WM_THREADMSG, 1, 0);
- TRACE("CConnectSocket() OnClose()\n");
- CSocket::OnClose(nErrorCode);
- }
- catch(...)
- {
- }
- }
- #define BUFFERSIZE 4096
- /********************************************************************/
- /* */
- /* Function name : OnReceive */
- /* Description : Called by the framework to notify this socket */
- /* that there is data in the buffer. */
- /* */
- /********************************************************************/
- //由主窗口调用通知套接字缓冲区中有数据要接收
- void CConnectSocket::OnReceive(int nErrorCode)
- {
- TCHAR buff[BUFFERSIZE];
- //接收数据并放到缓冲区
- int nRead = Receive(buff, BUFFERSIZE);
- switch (nRead)
- {
- case 0:
- Close();
- break;
- case SOCKET_ERROR:
- if (GetLastError() != WSAEWOULDBLOCK)
- {
- // TCHAR szError[256];
- // wsprintf(szError, "OnReceive error: %d", GetLastError());
- // AfxMessageBox (szError);
- }
- break;
- default:
- if (nRead != SOCKET_ERROR && nRead != 0)
- {
- ((CConnectThread *)AfxGetThread())->IncReceivedBytes(nRead);
- TMessageHeader *pMessageHeader = (TMessageHeader *)buff;
- /*网络字节顺序的转换*/
- ntohs(pMessageHeader->wHeaderFlag);
- ntohs(pMessageHeader->wMessageId);
- ntohs(pMessageHeader->wMessageSubId);
- ntohl(pMessageHeader->dwDataLen);
- ntohs(pMessageHeader->wCheckSum);
- ntohl(pMessageHeader->wReserve);
- if(pMessageHeader->wMessageId ==MSG_LOGIN_REQ)
- {
- WORD wMessageId = MSG_LOGIN_RESP;
- LOGIN_RESULT_STRU tLoginResult = {0};
- tLoginResult.tCommonMsg.dwConnectionID = 0;
- tLoginResult.tCommonMsg.wMessageId = wMessageId;
- tLoginResult.byResult = LOGIN_RESULT_SUC;
- tLoginResult.dwUserID = 0;
- tLoginResult.byStatus = USER_STATUS_ONLINE ;
- DWORD dwDataLen = sizeof(LOGIN_RESULT_STRU);
- TMessageHeader tHeader = {0};
- tHeader.wMessageId = wMessageId;
- tHeader.dwDataLen = dwDataLen;
- net_Send(&tHeader, (void *)&tLoginResult, dwDataLen);
- }
- else //if(pMessageHeader->wMessageId ==MSG_CHATMESSAGE_REQ)
- {
- /* char *pDataBuf = (char *)buff + MESSAGE_HEADER_LEN;
- TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf;
- DWORD dwConnectionID = pChatMessage->tCommonMsg.dwConnectionID;
- processChatMessageRequest((void *)pChatMessage);*/
- // 结束字符串
- if(pMessageHeader->wHeaderFlag==MESSAGE_HEADER_FLAG && pMessageHeader->wMessageId ==MSG_CHATMESSAGE_REQ)
- {
- if(m_pRevBuf)delete []m_pRevBuf;
- m_pRevBuf=NULL;
- m_reved=0;
- m_dateleng=0;
- m_dateleng=pMessageHeader->dwDataLen+MESSAGE_HEADER_LEN;
- m_pRevBuf=new BYTE[m_dateleng];
- //WriteLogin("开始接收");
- }
- if(m_dateleng==0)
- return;
- ::memcpy(m_pRevBuf+m_reved, buff, min(nRead, m_dateleng-m_reved));
- m_reved+=min(nRead, m_dateleng-m_reved);
- // CString ss;
- // ss.Format ("接收:%d/%d", m_reved, m_dateleng);
- // WriteLogin(ss);
- if(m_reved>=m_dateleng)
- {
- // WriteLogin("接收完成");
- char *pDataBuf = (char *)m_pRevBuf + MESSAGE_HEADER_LEN;
- TCHAT_MESSAGE_STRU *pChatMessage = (TCHAT_MESSAGE_STRU *)pDataBuf;
- m_reved=0;m_dateleng=0;
- processChatMessageRequest((void *)pChatMessage);
- }
- }
- }
- break;
- }
- CSocket::OnReceive(nErrorCode);
- }
- /********************************************************************/
- /* */
- /* Function name: GetRxCommand */
- /* Description : Get command from receiver buffer. */
- /* */
- /********************************************************************/
- //从接收缓冲区获得命令
- BOOL CConnectSocket::GetRxCommand(CString &strCommand, CString &strArguments)
- {
- return FALSE;
- }
- /********************************************************************/
- /* */
- /* Function name: GetRxLine */
- /* Description : Parse complete command line */
- /* */
- /********************************************************************/
- //解析整个命令行
- void CConnectSocket::GetRxLine()
- {
- }
- /********************************************************************/
- /* */
- /* Function name: OnConnect */
- /* Description : Called by the framework to notify this connecting */
- /* socket that its connection attempt is completed. */
- /* */
- /********************************************************************/
- void CConnectSocket::OnConnect(int nErrorCode)
- {
- CSocket::OnConnect(nErrorCode);
- }
- /********************************************************************/
- /* */
- /* Function name: HasConnectionDropped */
- /* Description : Check if connection has been dropped. */
- /* Used to detect if client has crashed. */
- /* */
- /********************************************************************/
- BOOL CConnectSocket::HasConnectionDropped(void)
- {
- try
- {
- BOOL bConnDropped = FALSE;
- INT iRet = 0;
- BOOL bOK = TRUE;
- if (m_hSocket == INVALID_SOCKET)
- return TRUE;
- struct timeval timeout = { 0, 0 };
- fd_set readSocketSet;
- FD_ZERO(&readSocketSet);
- FD_SET(m_hSocket, &readSocketSet);
- iRet = ::select(0, &readSocketSet, NULL, NULL, &timeout);
- bOK = (iRet > 0);
- if(bOK)
- {
- bOK = FD_ISSET(m_hSocket, &readSocketSet);
- }
- if(bOK)
- {
- CHAR szBuffer[1] = "";
- iRet = ::recv(m_hSocket, szBuffer, 1, MSG_PEEK);
- bOK = (iRet > 0);
- if(!bOK)
- {
- INT iError = ::WSAGetLastError();
- bConnDropped = (( iError == WSAENETRESET) ||
- (iError == WSAECONNABORTED) ||
- (iError == WSAECONNRESET) ||
- (iError == WSAEINVAL) ||
- (iRet == 0));
- }
- }
- return(bConnDropped);
- }
- catch(...)
- {
- }
- return 1;
- }
- /********************************************************************/
- /* */
- /* Function name: SendResponse */
- /* Description : Send response to client. */
- /* */
- /********************************************************************/
- //发送响应给客户端
- BOOL CConnectSocket::SendResponse(LPCTSTR pstrFormat, ...)
- {
- return TRUE;
- }
- //从客户端解析并执行命令
- void CConnectSocket::ParseCommand()
- {
- }
- /********************************************************************/
- /* */
- /* Function name: FireStatusMessage */
- /* Description : Fire status message. */
- /* */
- /********************************************************************/
- void CConnectSocket::FireStatusMessage(LPCTSTR lpszStatus, int nType)
- {
- try
- {
- g_pWndServer->AddTraceLine(nType, "[%d] %s", m_pThread->m_nThreadID, lpszStatus);
- }
- catch(...)
- {
- }
- }
- /********************************************************************/
- /* */
- /* Function name: CreateDataConnection */
- /* Description : Create data transfer connection. */
- /* */
- /********************************************************************/
- BOOL CConnectSocket::CreateDataConnection(int nTransferType, LPCTSTR lpszData)
- {
- return TRUE;
- }
- /********************************************************************/
- /* */
- /* Function name: DestroyDataConnection */
- /* Description : Close data transfer connection. */
- /* */
- /********************************************************************/
- void CConnectSocket::DestroyDataConnection()
- {
- }
- unsigned long CConnectSocket::net_Send(IN void *pHeader, IN void *pMessage, IN unsigned long ulDataLen)
- {
- try
- {
- unsigned long ulSendLen = 0;
- unsigned long ulBufLen = 0;
- TMessageHeader *pSendHeader = (TMessageHeader *)pHeader;
- ulBufLen = MESSAGE_HEADER_LEN + ulDataLen;
- char *pSendBuf = new char[ulBufLen];
- memset(pSendBuf, 0, ulBufLen);
- TMessageHeader *pMessageHeader = (TMessageHeader *)pSendBuf;
- pMessageHeader->byVersion = 101;
- pMessageHeader->wHeaderFlag = MESSAGE_HEADER_FLAG;
- pMessageHeader->wMessageId = pSendHeader->wMessageId;
- pMessageHeader->wMessageSubId = pSendHeader->wMessageSubId;
- pMessageHeader->dwDataLen = ulDataLen;
- pMessageHeader->wReserve = 0;
- memcpy((void *)(pSendBuf+MESSAGE_HEADER_LEN), pMessage, ulDataLen);
- // convert network word
- htons(pMessageHeader->wHeaderFlag);
- htons(pMessageHeader->wMessageId);
- htons(pMessageHeader->wMessageSubId);
- htonl(pMessageHeader->dwDataLen);
- htons(pMessageHeader->wCheckSum);
- htonl(pMessageHeader->wReserve);
- //Send the message
- // ulSendLen = CTransportImpl::net_Send(hSocket, (void *)pSendBuf, ulBufLen);
- //判断连接是否在活动状态
- if (HasConnectionDropped())
- {
- FireStatusMessage("Could not send reply, disconnected.", 2);
- Close();
- // 通知线程已经停止,关闭连接
- m_pThread->PostThreadMessage(WM_THREADMSG, 1, 0);
- return FALSE;
- }
- int nBytes = CSocket::Send((void *)pSendBuf, ulBufLen);
- if (nBytes == SOCKET_ERROR)
- {
- Close();
- FireStatusMessage("Could not send reply, disconnected.", 2);
- //通知线程连接已经关闭
- m_pThread->PostThreadMessage(WM_THREADMSG, 1, 0);
- return FALSE;
- }
- ((CConnectThread *)AfxGetThread())->IncSentBytes(nBytes);
- delete [] pSendBuf;
- pSendBuf = NULL;
- return nBytes;
- }
- catch(...)
- {
- }
- return 0;
- }
- BOOL g_bWork=0;
- extern int FindArray2(CStringArray *pArray, CString Str);
- extern CStringArray g_ipnoallowarray;
- void AddIP(CString ip)
- {
- MyLock lock("IsIPAddressAllowed");
- if(::FindArray2 (&g_ipnoallowarray, ip)!=-1)return;
- g_ipnoallowarray.Add (ip);
- WriteUnallowIP(ip);
- }
- void CConnectSocket::processChatMessageRequest(void *pChatMsg)
- {
- int pos = 0;
- CString str;
- CString g_ret;
- try
- {
- g_bWork=1;
- if( NULL == pChatMsg )
- {
- g_bWork=0;
- return;
- }
- TCHAT_MESSAGE_STRU *ptChatMessage = (TCHAT_MESSAGE_STRU *)pChatMsg;
- DWORD dwUserID = ptChatMessage->tCommonMsg.dwConnectionID;
- if(ptChatMessage->length[98]!=987123768)
- {
- WriteLogin("987123768");
- g_bWork=0;
- return;
- }
- int nMessageLen = ptChatMessage->wMessageLen;
- if( nMessageLen > 3 )
- {
- // MyLock lock("msgaccessdbsendreg");
- DWORD dwToUserID = ptChatMessage->dwToUserID;
- if(dwToUserID!=9)//企业版分店权限设置
- {
- char *szChatMessage;
- szChatMessage = new char[nMessageLen+1];
- memset(szChatMessage, 0x00, nMessageLen+1);
- memcpy(szChatMessage, ptChatMessage->byFileContent, nMessageLen);
- EncryptFile2((BYTE*)szChatMessage, nMessageLen, "888666333");
- str=szChatMessage;delete []szChatMessage;
- }
- else
- str.Empty ();
- BYTE *pBranchData=NULL;
- DWORD nBranchDataLeng=0;
- int nBranchArraySize=0;
- CString name;
- CString phone;
- CString signname;
- int nRoadType;
- // 解析过程;
- if(dwToUserID==0)
- {
- //MyLock lock("msgaccessdbsendreg");
- //WriteLogin("开始");
- WriteLogin(str);
- g_ret=str;
- // 短信账号、账号密码、手机串、短信内容、短信指定的发送时间;
- CString account,psw,phones,content,timestamp;
- pos=str.Find ("\r\n");
- if(pos==-1)
- {
- g_bWork=0;WriteLogin("返回1");
- return;
- }
- account=str.Left (pos);
- str.Delete (0, pos+2);
- pos=str.Find ("\r\n");
- if(pos==-1) {
- g_bWork=0;WriteLogin("返回2");
- return;
- }
- psw=str.Left (pos);
- str.Delete (0, pos+2);
- pos=str.Find ("\r\n");
- if(pos==-1) {
- g_bWork=0;WriteLogin("返回3");
- return;
- }
- phones=str.Left (pos);
- str.Delete (0, pos+2);
- pos=str.ReverseFind ('\r');
- if(pos==-1) {
- g_bWork=0;WriteLogin("返回4");
- return;
- }
- content=str.Left (pos);
- str.Delete (0, pos+2);
- timestamp=str;
- if(BadUser(account)) {
- g_bWork=0;WriteLogin("返回5");
- return;
- }
- // CheckUser(account, psw, name, phone, signname, m_pConndb, nRoadType);
- // if(account!="105828")//1)//
- if(CheckUser(account, psw, name, phone, signname, m_pConndb, nRoadType)==0)
- {
- // str="服务暂停!";
- str="账户或密码错误!";
- WritePswWrong(account+"\\"+psw+"\\"+name+"\\"+phone);
- WriteLogin(str);
- AddIP(((CConnectThread*)m_pThread)->m_strRemoteHost);
- }
- else // Jeff: 账号密码正确;
- {
- // 1.获取该账号的剩余短信数量;
- content += signname;
- int nMaxPhones = 100;
- if(content.Find ("财报:收:")!=-1) // Jeff:这是发给谁的?
- nMaxPhones=1;
- CString sql;
- int balance = GetBalance(account, m_pConndb); // Jeff:获取剩余短信数;(该函数计数非安全,造成结果值不对的原因是【msgcount】字段值不是100%正确)
- int count = GetCount(phones,content); // Jeff:返回发送到全部手机号的短信条数;
- if(0)//nMaxPhones!=1 && phones.Find (",")!=-1)
- {
- str="群发服务暂停!";
- }
- else
- {
- CString scount;
- scount.Format ("%d", count);
- if(balance<0 || count>balance)
- {
- str="发送信息失败! 余额不足!";
- WriteLogin(str);
- WriteNullBalance(account+"\\"+name+"\\"+phone);
- AddIP(((CConnectThread*)m_pThread)->m_strRemoteHost);
- }
- else
- {
- // Jeff Remark;
- // 1.如果短信内容转化为宽字符后的字符总数大于500,分割成每组500宽字符;
- CStringArray contentarray;
- // int leng[1]={70};
- int leng[1]={500}; // Jeff:500的作用?
- CStringArray *pArray[1]={&contentarray};
- for(int a=0; a<1; a++) // 为什么使用循环1次?
- {
- CString contenttemp = content;
- if(GetLengthEx(contenttemp) > leng[a])
- {
- while(GetLengthEx(contenttemp) > leng[a])
- {
- for( pos=leng[a]; pos<contenttemp.GetLength(); pos++)
- {
- if(GetLengthEx(contenttemp.Left(pos))==leng[a])
- {
- if((pos+1)<contenttemp.GetLength())
- {
- if(GetLengthEx(contenttemp.Left(pos+1))==leng[a])
- pos++;
- }
- break;
- }
- }
- if(pos==contenttemp.GetLength())
- {
- pArray[a]->Add (contenttemp);
- contenttemp.Empty ();
- break;
- }
- else
- {
- pArray[a]->Add (contenttemp.Left (pos));
- contenttemp=contenttemp.Right (contenttemp.GetLength ()-pos);
- }
- }
- if(!contenttemp.IsEmpty ())
- pArray[a]->Add (contenttemp);
- }
- else
- pArray[a]->Add (content);
- }
- g_ret+="\rstep1";
- // 2.解析手机串;
- CStringArray phonearray;
- pos=phones.Find (",");
- if(pos!=-1)
- {
- phonearray.Add(phones.Left (pos));
- phones=phones.Right (phones.GetLength ()-pos-1);
- pos=phones.Find (",");
- while(pos!=-1)
- {
- phonearray.Add (phones.Left (pos));
- if(phones.IsEmpty ()==0)
- phones=phones.Right (phones.GetLength ()-pos-1);
- pos=phones.Find (",");
- }
- phones.TrimLeft (",");
- if(phones.IsEmpty ()==0)
- phonearray.Add (phones);
- }
- else
- phonearray.Add (phones);
- g_ret+="\rstep2";
- // 3. 1,2,3,4分别为移动、联通、电信、小灵通;
- int phonearraysize1,phonearraysize2,phonearraysize3,phonearraysize4;
- CArray<CStringArray, CStringArray>multiphonearray1;
- CArray<CStringArray, CStringArray>multiphonearray2;
- CArray<CStringArray, CStringArray>multiphonearray3;
- CArray<CStringArray, CStringArray>multiphonearray4;
- phonearraysize1=phonearraysize2=phonearraysize3=phonearraysize4=1;
- multiphonearray1.SetSize(phonearraysize1, 1);multiphonearray1.ElementAt (0).RemoveAll();
- multiphonearray2.SetSize(phonearraysize2, 1);multiphonearray2.ElementAt (0).RemoveAll();
- multiphonearray3.SetSize(phonearraysize3, 1);multiphonearray3.ElementAt (0).RemoveAll();
- multiphonearray4.SetSize(phonearraysize4, 1);multiphonearray4.ElementAt (0).RemoveAll();
- int size[4]={1,1,1,1};
- CArray<CStringArray, CStringArray> *pPhoneArray[4]={&multiphonearray1,&multiphonearray2,&multiphonearray3,&multiphonearray4};
- int i ;
- for( i=0; i<phonearray.GetSize (); i++)
- {
- phones=phonearray.ElementAt (i);
- pos=CheckPhoneType(phones);
- if(pos==-1)continue;
- if(pPhoneArray[pos]->ElementAt (size[pos]-1).GetSize()>=nMaxPhones)
- {
- size[pos]++;
- pPhoneArray[pos]->SetSize(size[pos], 1);
- pPhoneArray[pos]->ElementAt (size[pos]-1).RemoveAll();
- pPhoneArray[pos]->ElementAt (size[pos]-1).Add (phones);
- }
- else
- {
- pPhoneArray[pos]->ElementAt (size[pos]-1).Add (phones);
- }
- }
- g_ret+="\rstep3";
- // 4.根据手机运营商,重新生成对应运营商的手机串;
- CString timestamp2,msgpos;
- CTime tm = CTime::GetCurrentTime();
- CTimeSpan dt(0,0,0,1);
- BOOL exist=0;
- for(i=0; i<4; i++)
- {
- for(int j=0; j<pPhoneArray[i]->GetSize(); j++)
- {
- if(!pPhoneArray[i]->ElementAt(j).GetSize())continue;
- phones.Empty();
- for(int n=0; n<pPhoneArray[i]->ElementAt(j).GetSize(); n++)
- {
- phones+=pPhoneArray[i]->ElementAt(j).ElementAt(n);
- phones+=",";
- }
- phones.TrimRight(",");
- if(i<3) // Jeff i < 3 :去除小灵通;
- {
- for(int m=0; m<contentarray.GetSize(); m++)
- {
- content=contentarray.ElementAt (m);
- int count = GetCount(phones,content); // Jeff:返回发送到全部手机号的短信条数;
- // count2+=count;
- CString scount;
- scount.Format("%d", count);
- if(IsExist(account,phones,content,timestamp,m_pConndb))
- {
- exist=1;
- continue;
- }
- msgpos.Format("%d", m);
- tm+=dt;
- timestamp2=tm.Format ("%Y%m%d%H%M%S"); // Jeff 字段[timestamp2]应该是短信被程序接收到的时间;
- sql="insert into sendreg([account],[phones],[content],[timestamp],[timestamp2],[msgcount],[msgcount2],[msgpos],[today]) values\
- ('"+account+"','"+phones+"','"+content+"','"+timestamp+"','"+timestamp2+"','"+scount+"','0','"+msgpos+"','"+tm.Format ("%Y-%m-%d")+"')";
- if(MyExecuteSQL(m_pConndb, sql)==0)
- {
- WriteLogin("信息写入数据库失败");
- return;
- }
- }
- }
- ::Sleep (500);
- }
- }
- g_ret+="\rstep4";
- str="发送信息成功!";
- WriteLogin(str);
- int ret1; // 账号可用的剩余短信数量;
- int ret2; // 账号已用的短信总数;
- GetBalanceUsed(account, ret1, ret2,m_pConndb); // Jeff,并将值更新到数据库表记录中;
- g_sendhead.length[0]=ret1;
- g_sendhead.length[1]=ret2;
- }
- }
- }
- }
- else if(dwToUserID==1)//改密码
- {
- CString account,psw,newpsw;
- int pos=str.Find ("\r\n");
- if(pos==-1)
- {
- g_bWork=0;
- return;
- }
- account=str.Left (pos);
- str.Delete (0, pos+2);
- pos=str.Find ("\r\n");
- if(pos==-1)
- {
- g_bWork=0;
- return;
- }
- psw=str.Left (pos);
- str.Delete (0, pos+2);
- newpsw=str;
- if(BadUser(account))
- {
- g_bWork=0;
- return;
- }
- if(CheckUser(account, psw, name, phone, signname, m_pConndb, nRoadType)==0)
- {
- str="账户或密码错误!";
- }
- else
- {
- WriteLog(account, "修改密码");
- CString sql;
- sql="update [clientinfo] set [psw]='"+newpsw+"' where [account]='"+account+"'";
- if(MyExecuteSQL(m_pConndb, sql))
- str="修改密码成功!";
- else
- str="修改密码失败!";
- }
- }
- else if(dwToUserID==2)//查询使用
- {
- CString account,psw,newpsw;
- int pos=str.Find ("\r\n");
- if(pos==-1) {
- g_bWork=0;
- return;
- }
- account=str.Left (pos);
- str.Delete (0, pos+2);
- psw=str;
- if(BadUser(account)) {
- g_bWork=0;
- return;
- }
- if(CheckUser(account, psw, name, phone, signname, m_pConndb, nRoadType)==0)
- {
- str="账户或密码错误!";
- }
- else
- {
- WriteLog(account, "查询使用");
- CString count2="";
- CString count3="";
- try
- {
- CRecordset myset(m_pConndb);
- CString sql;
- #ifdef SQLSERVER_VERSION
- sql="select sum(cast([msgcount] as float)) as cot from sendreg where account='"+account+"'";
- #else
- sql="select sum([msgcount]) as cot from sendreg where account='"+account+"'";
- #endif
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count2);
- myset.Close();
- #ifdef SQLSERVER_VERSION
- sql="select sum(cast([msgcount2] as float)) as cot from sendreg where account='"+account+"'";
- #else
- sql="select sum([msgcount2]) as cot from sendreg where account='"+account+"'";
- #endif
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count3);
- myset.Close();
- str.Format ("查询使用成功! 已使用:%d", atoi(count2) );
- }
- catch(...)
- {
- str="查询使用失败!";
- }
- }
- //WriteLogin(str);
- }
- else if(dwToUserID==3)//查询余额
- {
- CString account,psw,newpsw;
- int pos=str.Find ("\r\n");
- if(pos==-1) {
- g_bWork=0;
- return;
- }
- account=str.Left (pos);
- str.Delete (0, pos+2);
- psw=str;
- if(BadUser(account)) {
- g_bWork=0;
- return;
- }
- if(CheckUser(account, psw, name, phone, signname, m_pConndb, nRoadType)==0)
- {
- str="账户或密码错误!";
- }
- else
- {
- WriteLog(account, "查询余额");
- CString count1="";
- CString count2="";
- CString count3="";
- try
- {
- CRecordset myset(m_pConndb);
- #ifdef SQLSERVER_VERSION
- CString sql="select sum(cast([count] as float)) as cot from recharge where account='"+account+"'";
- #else
- CString sql="select sum([count]) as cot from recharge where account='"+account+"'";
- #endif
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count1);
- myset.Close();
- #ifdef SQLSERVER_VERSION
- sql="select sum(cast([msgcount] as float)) as cot from sendreg where account='"+account+"'";
- #else
- sql="select sum([msgcount]) as cot from sendreg where account='"+account+"'";
- #endif
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count2);
- myset.Close();
- #ifdef SQLSERVER_VERSION
- sql="select sum(cast([msgcount2] as float)) as cot from sendreg where account='"+account+"'";
- #else
- sql="select sum([msgcount2]) as cot from sendreg where account='"+account+"'";
- #endif
- myset.Open (CRecordset::forwardOnly, sql);
- if(!myset.IsEOF())
- myset.GetFieldValue ("cot", count3);
- myset.Close();
- str.Format ("查询余额成功! 可发信息数:%d", atoi(count1)- atoi(count2) );
- }
- catch(...)
- {
- str="查询余额失败!";
- }
- }
- //WriteLogin(str);
- }
- else if(dwToUserID==4)//查发送记录
- {
- MyLock lock("msgaccessdbsendlog");
- CString account,psw,timestamp;
- int pos=str.Find ("\r\n");
- if(pos==-1) {
- g_bWork=0;
- return;
- }
- account=str.Left (pos);
- str.Delete (0, pos+2);
- pos=str.Find ("\r\n");
- if(pos==-1) {
- g_bWork=0;
- return;
- }
- psw=str.Left (pos);
- str.Delete (0, pos+2);
- timestamp=str;
- if(BadUser(account)) {
- g_bWork=0;
- return;
- }
- if(CheckUser(account, psw, name, phone, signname, m_pConndb, nRoadType)==0)
- {
- str="账户或密码错误!";
- WritePswWrong(account+"\\"+psw+"\\"+name+"\\"+phone);AddIP(((CConnectThread*)m_pThread)->m_strRemoteHost);
- }
- else
- {
- WriteLog(account, "查询发送记录");
- str.Empty ();
- // MyLock lock("xiaoaccessdbmsg");
- for(int i=0; i<timestamp.GetLength ()/14; i++)
- {
- int count=0;
- int count2=0;
- CString temp=timestamp.Mid (i*14, 14);
- RstSendReg rsSt;
- rsSt.m_pDatabase=m_pConndb;
- rsSt.m_strFilter = "[account]='"+account+"' and [timestamp]='"+temp+"'";
- rsSt.Open();
- while(!rsSt.IsEOF())
- {
- if(atoi(rsSt.m_msgcount2))
- count++;
- count2++;
- rsSt.MoveNext ();
- }
- rsSt.Close();
- temp.Format ("%d/%d,", count, count2);
- str+=temp;
- }
- str.TrimRight (",");
- }
- }
- else if(dwToUserID==20)//查回复
- {
- CString account,psw,timestamp;
- int pos=str.Find ("\r\n");
- if(pos==-1) {
- g_bWork=0;
- return;
- }
- account=str.Left (pos);
- str.Delete (0, pos+2);
- pos=str.Find ("\r\n");
- if(pos==-1) {
- g_bWork=0;
- return;
- }
- psw=str.Left (pos);
- str.Delete (0, pos+2);
- if(BadUser(account)) {
- g_bWork=0;
- return;
- }
- if(CheckUser(account, psw, name, phone, signname, m_pConndb, nRoadType)==0)
- {
- str="账户或密码错误!";
- WritePswWrong(account+"\\"+psw+"\\"+name+"\\"+phone);AddIP(((CConnectThread*)m_pThread)->m_strRemoteHost);
- }
- else
- {
- if(nRoadType==2)
- str="未启用";
- else
- {
- WriteLog(account, "查询客人回复记录");
- str.Empty ();
- CString temp;
- ReceiveMsgForm rsSt;
- rsSt.m_pDatabase=m_pConndb;
- rsSt.m_strFilter = "[account]='"+account+"' and replyok is null";
- rsSt.Open();
- while(!rsSt.IsEOF())
- {
- temp=rsSt.m_phone;
- temp+="'";
- temp+=rsSt.m_content;
- temp+="'";
- temp+=rsSt.m_datetime;
- temp+="'";
- temp+=rsSt.m_autoid;
- rsSt.MoveNext();
- str+=temp;
- str+="^";
- }
- rsSt.Close();
- if(str=="")
- str="无回复";
- }
- }
- }
- else if(dwToUserID==21)//更改回复状态,已收到
- {
- CString account,psw,sids;
- int pos=str.Find ("\r\n");
- if(pos==-1) {
- g_bWork=0;
- return;
- }
- account=str.Left (pos);
- str.Delete (0, pos+2);
- pos=str.Find ("\r\n");
- if(pos==-1) {
- g_bWork=0;
- return;
- }
- psw=str.Left (pos);
- str.Delete (0, pos+2);
- sids=str;
- if(BadUser(account)) {
- g_bWork=0;
- return;
- }
- if(CheckUser(account, psw, name, phone, signname, m_pConndb, nRoadType)==0)
- {
- str="账户或密码错误!";
- WritePswWrong(account+"\\"+psw+"\\"+name+"\\"+phone);AddIP(((CConnectThread*)m_pThread)->m_strRemoteHost);
- }
- else
- {
- str.Format ("update receivemsg set replyok=1 where %s", sids);
- MyExecuteSQL(m_pConndb, str);
- str="ok";
- }
- }
- else if(dwToUserID==5)//查询余额
- {
- CString account,psw,newpsw;
- int pos=str.Find ("\r\n");
- if(pos==-1) {
- g_bWork=0;
- return;
- }
- account=str.Left (pos);
- str.Delete (0, pos+2);
- psw=str;
- if(BadUser(account)) {
- g_bWork=0;
- return;
- }
- // ReCalAccount(account,m_pConndb);
- if(CheckUser(account, psw, name, phone, signname, m_pConndb, nRoadType)==0)
- {
- str="账户或密码错误!";
- }
- else
- {
- // CString count1="";
- // CString count2="";
- int ncount1=0;
- int ncount2=0;
- GetBalanceUsed(account, ncount1, ncount2, m_pConndb);
- // ncount1=atoi(count1)- atoi(count2);
- // ncount2= atoi(count2) ;
- str.Format ("%d/%d", ncount1, ncount2);
- }
- //WriteLogin("查询余额:"+str);
- }
- else if(dwToUserID==6)//登记客人IP
- {
- }
- else if(dwToUserID==7)//查询客人IP
- {
- }
- else if(dwToUserID==8)//企业版客人查询企业资料
- {
- }
- else if(dwToUserID==9)//企业版分店权限设置
- {
- }
- else if(dwToUserID==10)//登记客人IP
- {
- }
- else if(dwToUserID==11)//查询客人IP
- {
- }
- else if(dwToUserID==12)//执行sql
- {
- m_pConndb->ExecuteSQL (str);str="ok";
- }
- else if(dwToUserID==13)//查询sql
- {
- }
- DWORD dwFromUserID = dwUserID;
- WORD wMessageId = MSG_CHATMESSAGE_RESP;
- DWORD dwDataLen;
- BYTE *pSendData;
- TCHAT_MESSAGE_STRU *pChatMessage;
- if(str.IsEmpty ())str="OK";
- int nDataLen=str.GetLength ();
- if(nBranchDataLeng)
- {
- nDataLen=nBranchDataLeng;
- g_sendhead.count[0]=nBranchArraySize;
- }
- dwDataLen = sizeof(TCHAT_MESSAGE_STRU) + nDataLen ;
- TMessageHeader tHeader = {0};
- tHeader.wMessageId = wMessageId;
- tHeader.dwDataLen = dwDataLen;
- pSendData = new BYTE[dwDataLen];
- pChatMessage=(TCHAT_MESSAGE_STRU*)pSendData;
- memset(pChatMessage, 0x00, dwDataLen);
- memcpy(pSendData, &g_sendhead, sizeof(g_sendhead));
- pChatMessage->tCommonMsg.dwConnectionID = dwFromUserID;
- pChatMessage->tCommonMsg.wMessageId = wMessageId;
- pChatMessage->dwFromUserID = dwFromUserID;
- pChatMessage->dwToUserID = dwToUserID;
- pChatMessage->wMessageLen = nDataLen;
- if(nBranchDataLeng)
- {
- memcpy(pChatMessage->byFileContent, pBranchData, nDataLen); delete []pBranchData;
- }
- else
- {
- memcpy(pChatMessage->byFileContent, str.GetBuffer (0), nDataLen);
- str.ReleaseBuffer ();
- }
- net_Send(&tHeader, (void *)pChatMessage, dwDataLen);
- delete [] pSendData;
- }
- }
- catch(...)
- {
- WriteLogin("发送过程中出错:"+g_ret);
- }
- g_bWork=0;
- }
- void Test()
- {
- }
- //密码错误
|