码迷,mamicode.com
首页 > 数据库 > 详细

收藏一个c++连接数据库的类

时间:2014-12-11 15:14:42      阅读:973      评论:0      收藏:0      [点我收藏+]

标签:des   android   style   blog   http   io   ar   color   os   

DataBaseEngine.cpp:

bubuko.com,布布扣
  1 #include "StdAfx.h"
  2 #include "Math.h"
  3 #include "EventService.h"
  4 #include "DataBaseEngine.h"
  5 
  6 //////////////////////////////////////////////////////////////////////////
  7 
  8 //宏定义
  9 _COM_SMARTPTR_TYPEDEF(IADORecordBinding,__uuidof(IADORecordBinding));
 10 
 11 //效验结果宏
 12 #define EfficacyResult(hResult) { if (FAILED(hResult)) _com_issue_error(hResult); }
 13 
 14 //////////////////////////////////////////////////////////////////////////
 15 
 16 //构造函数
 17 CADOError::CADOError()
 18 {
 19     m_enErrorType=ErrorType_Nothing;
 20 }
 21 
 22 //析构函数
 23 CADOError::~CADOError()
 24 {
 25 }
 26 
 27 //接口查询
 28 void * __cdecl CADOError::QueryInterface(const IID & Guid, DWORD dwQueryVer)
 29 {
 30     QUERYINTERFACE(IADOError,Guid,dwQueryVer);
 31     QUERYINTERFACE_IUNKNOWNEX(IADOError,Guid,dwQueryVer);
 32     return NULL;
 33 }
 34 
 35 //设置错误
 36 void CADOError::SetErrorInfo(enADOErrorType enErrorType, LPCTSTR pszDescribe)
 37 {
 38     //设置错误
 39     m_enErrorType=enErrorType;
 40     m_strErrorDescribe=pszDescribe;
 41 
 42     //抛出错误
 43     throw GET_MYSELF_INTERFACE(IADOError);
 44 
 45     return;
 46 }
 47 
 48 //////////////////////////////////////////////////////////////////////////
 49 
 50 //构造函数
 51 CDataBase::CDataBase() : m_dwResumeConnectCount(30L),m_dwResumeConnectTime(30L)
 52 {
 53     //状态变量
 54     m_dwConnectCount=0;
 55     m_dwConnectErrorTime=0L;
 56 
 57     //创建对象
 58     m_DBCommand.CreateInstance(__uuidof(Command));
 59     m_DBRecordset.CreateInstance(__uuidof(Recordset));
 60     m_DBConnection.CreateInstance(__uuidof(Connection));
 61 
 62     //效验数据
 63     ASSERT(m_DBCommand!=NULL);
 64     ASSERT(m_DBRecordset!=NULL);
 65     ASSERT(m_DBConnection!=NULL);
 66     if (m_DBCommand==NULL) throw TEXT("数据库命令对象创建失败");
 67     if (m_DBRecordset==NULL) throw TEXT("数据库记录集对象创建失败");
 68     if (m_DBConnection==NULL) throw TEXT("数据库连接对象创建失败");
 69 
 70     //设置变量
 71     m_DBCommand->CommandType=adCmdStoredProc;
 72 
 73     return;
 74 }
 75 
 76 //析构函数
 77 CDataBase::~CDataBase()
 78 {
 79     //关闭连接
 80     CloseConnection();
 81 
 82     //释放对象
 83     m_DBCommand.Release();
 84     m_DBRecordset.Release();
 85     m_DBConnection.Release();
 86 
 87     return;
 88 }
 89 
 90 //接口查询
 91 void * __cdecl CDataBase::QueryInterface(const IID & Guid, DWORD dwQueryVer)
 92 {
 93     QUERYINTERFACE(IDataBase,Guid,dwQueryVer);
 94     QUERYINTERFACE_IUNKNOWNEX(IDataBase,Guid,dwQueryVer);
 95     return NULL;
 96 }
 97 
 98 //打开连接
 99 bool __cdecl CDataBase::OpenConnection()
100 {
101     //连接数据库
102     try
103     {
104         //关闭连接
105         CloseConnection();
106 
107         //连接数据库
108         EfficacyResult(m_DBConnection->Open(_bstr_t(m_strConnect),L"",L"",adConnectUnspecified));
109         m_DBConnection->CursorLocation=adUseClient;
110         m_DBCommand->ActiveConnection=m_DBConnection;
111 
112         //设置变量
113         m_dwConnectCount=0L;
114         m_dwConnectErrorTime=0L;
115 
116         return true;
117     }
118     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
119 
120     return false;
121 }
122 
123 //关闭记录
124 bool __cdecl CDataBase::CloseRecordset()
125 {
126     try 
127     {
128         if (IsRecordsetOpened()) EfficacyResult(m_DBRecordset->Close());
129         return true;
130     }
131     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
132 
133     return false;
134 }
135 
136 //关闭连接
137 bool __cdecl CDataBase::CloseConnection()
138 {
139     try
140     {
141         CloseRecordset();
142         if ((m_DBConnection!=NULL)&&(m_DBConnection->GetState()!=adStateClosed))
143         {
144             EfficacyResult(m_DBConnection->Close());
145         }
146         return true;
147     }
148     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
149 
150     return false;
151 }
152 
153 //重新连接
154 bool __cdecl CDataBase::TryConnectAgain(bool bFocusConnect, CComError * pComError)
155 {
156     try
157     {
158         //判断重连
159         bool bReConnect=bFocusConnect;
160         if (bReConnect==false)
161         {
162             DWORD dwNowTime=(DWORD)time(NULL);
163             if ((m_dwConnectErrorTime+m_dwResumeConnectTime)>dwNowTime) bReConnect=true;
164         }
165         if ((bReConnect==false)&&(m_dwConnectCount>m_dwResumeConnectCount)) bReConnect=true;
166 
167         //设置变量
168         m_dwConnectCount++;
169         m_dwConnectErrorTime=(DWORD)time(NULL);
170         if (bReConnect==false)
171         {
172             if (pComError!=NULL) SetErrorInfo(ErrorType_Connect,GetComErrorDescribe(*pComError));
173             return false;
174         }
175 
176         //重新连接
177         OpenConnection();
178         return true;
179     }
180     catch (IADOError * pIADOError)
181     {
182         //重新连接错误
183         if (pComError!=NULL) SetErrorInfo(ErrorType_Connect,GetComErrorDescribe(*pComError));
184         else throw pIADOError;
185     }
186 
187     return false;
188 }
189 
190 //设置信息
191 bool __cdecl CDataBase::SetConnectionInfo(LPCTSTR szIP, WORD wPort, LPCTSTR szData, LPCTSTR szName, LPCTSTR szPass)
192 {
193     //效验参数 
194     ASSERT(szIP!=NULL);
195     ASSERT(szData!=NULL);
196     ASSERT(szName!=NULL);
197     ASSERT(szPass!=NULL);
198 
199     //构造连接字符串
200     m_strConnect.Format(TEXT("Provider=SQLOLEDB.1;Password=%s;Persist Security Info=True;User ID=%s;Initial Catalog=%s;Data Source=%s,%ld;"),
201         szPass,szName,szData,szIP,wPort);
202 
203     return true;
204 }
205 
206 //是否连接错误
207 bool __cdecl CDataBase::IsConnectError()
208 {
209     try 
210     {
211         //状态判断
212         if (m_DBConnection==NULL) return true;
213         if (m_DBConnection->GetState()==adStateClosed) return true;
214 
215         //参数判断
216         long lErrorCount=m_DBConnection->Errors->Count;
217         if (lErrorCount>0L)
218         {
219             ErrorPtr pError=NULL;
220             for(long i=0;i<lErrorCount;i++)
221             {
222                 pError=m_DBConnection->Errors->GetItem(i);
223                 if (pError->Number==0x80004005) return true;
224             }
225         }
226 
227         return false;
228     }
229     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
230 
231     return false;
232 }
233 
234 //是否打开
235 bool __cdecl CDataBase::IsRecordsetOpened()
236 {
237     if (m_DBRecordset==NULL) return false;
238     if (m_DBRecordset->GetState()==adStateClosed) return false;
239     return true;
240 }
241 
242 //往下移动
243 void __cdecl CDataBase::MoveToNext()
244 {
245     try 
246     { 
247         m_DBRecordset->MoveNext(); 
248     }
249     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
250 
251     return;
252 }
253 
254 //移到开头
255 void __cdecl CDataBase::MoveToFirst()
256 {
257     try 
258     { 
259         m_DBRecordset->MoveFirst(); 
260     }
261     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
262 
263     return;
264 }
265 
266 //是否结束
267 bool __cdecl CDataBase::IsEndRecordset()
268 {
269     try 
270     {
271         return (m_DBRecordset->EndOfFile==VARIANT_TRUE); 
272     }
273     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
274 
275     return true;
276 }
277 
278 //获取数目
279 long __cdecl CDataBase::GetRecordCount()
280 {
281     try
282     {
283         if (m_DBRecordset==NULL) return 0;
284         return m_DBRecordset->GetRecordCount();
285     }
286     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
287 
288     return 0;
289 }
290 
291 //获取大小
292 long __cdecl CDataBase::GetActualSize(LPCTSTR pszParamName)
293 {
294     ASSERT(pszParamName!=NULL);
295     try 
296     {
297         return m_DBRecordset->Fields->Item[pszParamName]->ActualSize;
298     }
299     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
300 
301     return -1;
302 }
303 
304 //绑定对象
305 bool __cdecl CDataBase::BindToRecordset(CADORecordBinding * pBind)
306 {
307     ASSERT(pBind!=NULL);
308     try 
309     {
310         IADORecordBindingPtr pIBind(m_DBRecordset);
311         pIBind->BindToRecordset(pBind);
312         return true;
313     }
314     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
315 
316     return false;
317 }
318 
319 //获取参数
320 bool __cdecl CDataBase::GetFieldValue(LPCTSTR lpFieldName, BYTE & bValue)
321 {
322     try
323     {
324         bValue=0;
325         _variant_t vtFld=m_DBRecordset->Fields->GetItem(lpFieldName)->Value;
326         switch(vtFld.vt)
327         {
328         case VT_BOOL:
329             {
330                 bValue=(vtFld.boolVal!=0)?1:0;
331                 break;
332             }
333         case VT_I2:
334         case VT_UI1:
335             {
336                 bValue=(vtFld.iVal>0)?1:0;
337                 break;
338             }
339         case VT_NULL:
340         case VT_EMPTY:
341             {
342                 bValue=0;
343                 break;
344             }
345         default: bValue=(BYTE)vtFld.iVal;
346         }    
347         return true;
348     }
349     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
350 
351     return false;
352 }
353 
354 //获取参数
355 bool __cdecl CDataBase::GetFieldValue(LPCTSTR lpFieldName, UINT & ulValue)
356 {
357     try
358     {
359         ulValue=0L;
360         _variant_t vtFld=m_DBRecordset->Fields->GetItem(lpFieldName)->Value;
361         if ((vtFld.vt!=VT_NULL)&&(vtFld.vt!=VT_EMPTY)) ulValue=vtFld.lVal;
362         return true;
363     }
364     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
365 
366     return false;
367 }
368 
369 //获取参数
370 bool __cdecl CDataBase::GetFieldValue(LPCTSTR lpFieldName, DOUBLE & dbValue)
371 {    
372     try
373     {
374         dbValue=0.0L;
375         _variant_t vtFld=m_DBRecordset->Fields->GetItem(lpFieldName)->Value;
376         switch(vtFld.vt)
377         {
378         case VT_R4:
379             {
380                 dbValue=vtFld.fltVal;
381                 break;
382             }
383         case VT_R8:
384             {
385                 dbValue=vtFld.dblVal;
386                 break;
387             }
388         case VT_DECIMAL:
389             {
390                 dbValue=vtFld.decVal.Lo32;
391                 dbValue*=(vtFld.decVal.sign==128)?-1:1;
392                 dbValue/=pow((float)10,vtFld.decVal.scale); 
393                 break;
394             }
395         case VT_UI1:
396             {
397                 dbValue=vtFld.iVal;
398                 break;
399             }
400         case VT_I2:
401         case VT_I4:
402             {
403                 dbValue=vtFld.lVal;
404                 break;
405             }
406         case VT_NULL:
407         case VT_EMPTY:
408             {
409                 dbValue=0.0L;
410                 break;
411             }
412         default: dbValue=vtFld.dblVal;
413         }
414         return true;
415     }
416     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
417 
418     return false;
419 }
420 
421 //获取参数
422 bool __cdecl CDataBase::GetFieldValue(LPCTSTR lpFieldName, LONG & lValue)
423 {
424     try
425     {
426         lValue=0L;
427         _variant_t vtFld=m_DBRecordset->Fields->GetItem(lpFieldName)->Value;
428         if ((vtFld.vt!=VT_NULL)&&(vtFld.vt!=VT_EMPTY)) lValue=vtFld.lVal;
429         return true;
430     }
431     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
432 
433     return false;
434 }
435 
436 //获取参数
437 bool __cdecl CDataBase::GetFieldValue(LPCTSTR lpFieldName, DWORD & ulValue)
438 {
439     try
440     {
441         ulValue=0L;
442         _variant_t vtFld=m_DBRecordset->Fields->GetItem(lpFieldName)->Value;
443         if ((vtFld.vt!=VT_NULL)&&(vtFld.vt!=VT_EMPTY)) ulValue=vtFld.ulVal;
444         return true;
445     }
446     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
447 
448     return false;
449 }
450 
451 //获取参数
452 bool __cdecl CDataBase::GetFieldValue(LPCTSTR lpFieldName, INT & nValue)
453 {
454     try
455     {
456         nValue=0;
457         _variant_t vtFld = m_DBRecordset->Fields->GetItem(lpFieldName)->Value;
458         switch(vtFld.vt)
459         {
460         case VT_BOOL:
461             {
462                 nValue = vtFld.boolVal;
463                 break;
464             }
465         case VT_I2:
466         case VT_UI1:
467             {
468                 nValue = vtFld.iVal;
469                 break;
470             }
471         case VT_NULL:
472         case VT_EMPTY:
473             {
474                 nValue = 0;
475                 break;
476             }
477         default: nValue = vtFld.iVal;
478         }    
479         return true;
480     }
481     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
482 
483     return false;
484 }
485 
486 //获取参数
487 bool __cdecl CDataBase::GetFieldValue(LPCTSTR lpFieldName, __int64 & llValue)
488 {
489     try
490     {
491         llValue=0L;
492         _variant_t vtFld=m_DBRecordset->Fields->GetItem(lpFieldName)->Value;
493         if ((vtFld.vt!=VT_NULL)&&(vtFld.vt!=VT_EMPTY)) llValue=vtFld.llVal;
494         return true;
495     }
496     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
497 
498     return false;
499 }
500 
501 //获取参数
502 bool __cdecl CDataBase::GetFieldValue(LPCTSTR lpFieldName, TCHAR szBuffer[], UINT uSize)
503 {
504     try
505     {
506         _variant_t vtFld=m_DBRecordset->Fields->GetItem(lpFieldName)->Value;
507         if (vtFld.vt==VT_BSTR)
508         {
509             lstrcpy(szBuffer,(char*)_bstr_t(vtFld));
510             return true;
511         }
512         return false;
513     }
514     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
515 
516     return false;
517 }
518 
519 //获取参数
520 bool __cdecl CDataBase::GetFieldValue(LPCTSTR lpFieldName, WORD & wValue)
521 {
522     try
523     {
524         wValue=0L;
525         _variant_t vtFld=m_DBRecordset->Fields->GetItem(lpFieldName)->Value;
526         if ((vtFld.vt!=VT_NULL)&&(vtFld.vt!=VT_EMPTY)) wValue=(WORD)vtFld.ulVal;
527         return true;
528     }
529     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
530 
531     return false;
532 }
533 
534 //获取参数
535 bool __cdecl CDataBase::GetFieldValue(LPCTSTR lpFieldName, COleDateTime & Time)
536 {
537     try
538     {
539         _variant_t vtFld = m_DBRecordset->Fields->GetItem(lpFieldName)->Value;
540         switch(vtFld.vt) 
541         {
542         case VT_DATE:
543             {
544                 COleDateTime TempTime(vtFld);
545                 Time=TempTime;
546                 break;
547             }
548         case VT_EMPTY:
549         case VT_NULL:
550             {
551                 Time.SetStatus(COleDateTime::null);
552                 break;
553             }
554         default: return false;
555         }
556         return true;
557     }
558     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
559 
560     return false;
561 }
562 
563 //获取参数
564 bool __cdecl CDataBase::GetFieldValue(LPCTSTR lpFieldName, bool & bValue)
565 {
566     try
567     {
568         _variant_t vtFld=m_DBRecordset->Fields->GetItem(lpFieldName)->Value;
569         switch(vtFld.vt) 
570         {
571         case VT_BOOL:
572             {
573                 bValue=(vtFld.boolVal==0)?false:true;
574                 break;
575             }
576         case VT_EMPTY:
577         case VT_NULL:
578             {
579                 bValue = false;
580                 break;
581             }
582         default:return false;
583         }
584         return true;
585     }
586     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
587 
588     return false;
589 }
590 
591 //获取返回数值
592 long __cdecl CDataBase::GetReturnValue()
593 {
594     try 
595     {
596         _ParameterPtr Parameter;
597         long lParameterCount=m_DBCommand->Parameters->Count;
598         for (long i=0;i<lParameterCount;i++)
599         {
600             Parameter=m_DBCommand->Parameters->Item[i];
601             if (Parameter->Direction==adParamReturnValue) return Parameter->Value.lVal;
602         }
603         ASSERT(FALSE);
604     }
605     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
606 
607     return 0;
608 }
609 
610 //删除参数
611 void __cdecl CDataBase::ClearAllParameters()
612 {
613     try 
614     {
615         long lParameterCount=m_DBCommand->Parameters->Count;
616         if (lParameterCount>0L)
617         {
618             for (long i=lParameterCount;i>0;i--)
619             {
620                 m_DBCommand->Parameters->Delete(i-1);
621             }
622         }
623     }
624     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
625 
626     return;
627 }
628 
629 //设置存储过程
630 void __cdecl CDataBase::SetSPName(LPCTSTR pszSpName)
631 {
632     ASSERT(pszSpName!=NULL);
633     try 
634     { 
635         m_DBCommand->CommandText=pszSpName; 
636     }
637     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
638 
639     return;
640 }
641 
642 //获得参数
643 void __cdecl CDataBase::GetParameterValue(LPCTSTR pszParamName, _variant_t & vtValue)
644 {
645     //效验参数
646     ASSERT(pszParamName!=NULL);
647 
648     //获取参数
649     try 
650     {
651         vtValue.Clear();
652         vtValue=m_DBCommand->Parameters->Item[pszParamName]->Value;
653     }
654     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
655 
656     return;
657 }
658 
659 //插入参数
660 void __cdecl CDataBase::AddParamter(LPCTSTR pszName, ADOCG::ParameterDirectionEnum Direction, ADOCG::DataTypeEnum Type, long lSize, _variant_t & vtValue)
661 {
662     ASSERT(pszName!=NULL);
663     try 
664     {
665         _ParameterPtr Parameter=m_DBCommand->CreateParameter(pszName,Type,Direction,lSize,vtValue);
666         m_DBCommand->Parameters->Append(Parameter);
667     }
668     catch (CComError & ComError) { SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError)); }
669 
670     return;
671 }
672 
673 //执行语句
674 bool __cdecl CDataBase::Execute(LPCTSTR pszCommand)
675 {
676     ASSERT(pszCommand!=NULL);
677     try
678     {
679         m_DBConnection->CursorLocation=adUseClient;
680         m_DBConnection->Execute(pszCommand,NULL,adExecuteNoRecords);
681         return true;
682     }
683     catch (CComError & ComError) 
684     { 
685         if (IsConnectError()==true)    TryConnectAgain(false,&ComError);
686         else SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError));
687     }
688 
689     return false;
690 }
691 
692 //执行命令
693 bool __cdecl CDataBase::ExecuteCommand(bool bRecordset)
694 {
695     try 
696     {
697         //关闭记录集
698         CloseRecordset();
699 
700         //执行命令
701         if (bRecordset==true)
702         {
703             m_DBRecordset->PutRefSource(m_DBCommand);
704             m_DBRecordset->CursorLocation=adUseClient;
705             EfficacyResult(m_DBRecordset->Open((IDispatch *)m_DBCommand,vtMissing,adOpenForwardOnly,adLockReadOnly,adOptionUnspecified));
706         }
707         else 
708         {
709             m_DBConnection->CursorLocation=adUseClient;
710             EfficacyResult(m_DBCommand->Execute(NULL,NULL,adExecuteNoRecords));
711         }
712         return true;
713     }
714     catch (CComError & ComError) 
715     { 
716         if (IsConnectError()==true)    TryConnectAgain(false,&ComError);
717         else SetErrorInfo(ErrorType_Other,GetComErrorDescribe(ComError));
718     }
719 
720     return false;
721 }
722 
723 //获取错误
724 LPCTSTR CDataBase::GetComErrorDescribe(CComError & ComError)
725 {
726     _bstr_t bstrDescribe(ComError.Description());
727     m_strErrorDescribe.Format(TEXT("ADO 错误:0x%8x,%s"),ComError.Error(),(LPCTSTR)bstrDescribe);
728     return m_strErrorDescribe;
729 }
730 
731 //设置错误
732 void CDataBase::SetErrorInfo(enADOErrorType enErrorType, LPCTSTR pszDescribe)
733 {
734     m_ADOError.SetErrorInfo(enErrorType,pszDescribe);
735     return;
736 }
737 
738 //////////////////////////////////////////////////////////////////////////
739 
740 //构造函数
741 CDataBaseEngine::CDataBaseEngine(void)
742 {
743     //设置变量
744     m_bService=false;
745     m_pIDataBaseSink=NULL;
746 
747     return;
748 }
749 
750 //析构函数
751 CDataBaseEngine::~CDataBaseEngine(void)
752 {
753 }
754 
755 //接口查询
756 void * __cdecl CDataBaseEngine::QueryInterface(const IID & Guid, DWORD dwQueryVer)
757 {
758     QUERYINTERFACE(IDataBaseEngine,Guid,dwQueryVer);
759     QUERYINTERFACE(IQueueServiceSink,Guid,dwQueryVer);
760     QUERYINTERFACE_IUNKNOWNEX(IDataBaseEngine,Guid,dwQueryVer);
761     return NULL;
762 }
763 
764 //注册接口
765 bool __cdecl CDataBaseEngine::SetDataBaseSink(IUnknownEx * pIUnknownEx)
766 {
767     //效验参数
768     ASSERT(pIUnknownEx!=NULL);
769     ASSERT(m_pIDataBaseSink==NULL);
770     if (pIUnknownEx==NULL) return false;
771     if (m_pIDataBaseSink!=NULL) return false;
772 
773     //查询接口
774     m_pIDataBaseSink=GET_OBJECTPTR_INTERFACE(pIUnknownEx,IDataBaseSink);
775     if (m_pIDataBaseSink==NULL)
776     {
777         CEventTrace::ShowEventNotify(TEXT("数据库引擎外挂服务接口获取失败,挂接操作失败"),Level_Exception);
778         return false;
779     }
780 
781     return true;
782 }
783 
784 //获取接口
785 void * __cdecl CDataBaseEngine::GetQueueService(const IID & Guid, DWORD dwQueryVer)
786 {
787     return m_RequestQueueService.QueryInterface(Guid,dwQueryVer);
788 }
789 
790 //启动服务
791 bool __cdecl CDataBaseEngine::StartService()
792 {
793     //判断状态
794     if (m_bService==true) 
795     {
796         CEventTrace::ShowEventNotify(TEXT("数据库引擎重复启动,启动操作忽略"),Level_Warning);
797         return true;
798     }
799 
800     //外挂接口
801     if (m_pIDataBaseSink==NULL)
802     {
803         CEventTrace::ShowEventNotify(TEXT("数据库引擎外挂服务不存在"),Level_Exception);
804         return false;
805     }
806 
807     //设置队列
808     if (m_RequestQueueService.SetQueueServiceSink(GET_MYSELF_INTERFACE(IUnknownEx))==false)
809     {
810         CEventTrace::ShowEventNotify(TEXT("数据库引擎与队列服务绑定失败"),Level_Exception);
811         return false;
812     }
813 
814     //启动外挂
815     if (m_pIDataBaseSink->StartService(GET_MYSELF_INTERFACE(IUnknownEx))==false)
816     {
817         CEventTrace::ShowEventNotify(TEXT("数据库引擎外挂服务启动失败"),Level_Exception);
818         return false;
819     }
820 
821     //启动队列
822     if (m_RequestQueueService.StartService()==false)
823     {
824         CEventTrace::ShowEventNotify(TEXT("数据库引擎队列服务启动失败"),Level_Exception);
825         return false;
826     }
827 
828     //设置变量
829     m_bService=true;
830 
831     return true;
832 }
833 
834 //停止服务
835 bool __cdecl CDataBaseEngine::StopService()
836 {
837     //设置变量
838     m_bService=false;
839 
840     //停止请求队列
841     m_RequestQueueService.StopService();
842 
843     //停止外挂
844     if (m_pIDataBaseSink!=NULL)
845     {
846         m_pIDataBaseSink->StopService(GET_MYSELF_INTERFACE(IUnknownEx));
847     }
848 
849     return true;
850 }
851 
852 //队列接口
853 void __cdecl CDataBaseEngine::OnQueueServiceSink(WORD wIdentifier, void * pBuffer, WORD wDataSize, DWORD dwInsertTime)
854 {
855     //判断状态
856     if (m_bService==false) return;
857 
858     //请求处理
859     switch (wIdentifier)
860     {
861     case EVENT_DATABASE:
862         {
863             //效验参数
864             ASSERT(pBuffer!=NULL);
865             ASSERT(wDataSize>=sizeof(NTY_DataBaseEvent));
866             if (wDataSize<sizeof(NTY_DataBaseEvent)) return;
867 
868             //变量定义
869             NTY_DataBaseEvent * pDataBaseEvent=(NTY_DataBaseEvent *)pBuffer;
870             WORD wHandleBuffer=wDataSize-sizeof(NTY_DataBaseEvent);
871 
872             //处理数据
873             ASSERT(m_pIDataBaseSink!=NULL);
874             m_pIDataBaseSink->OnDataBaseRequest(*pDataBaseEvent,pDataBaseEvent+1,wHandleBuffer);
875 
876             return;
877         }
878     }
879 
880     return;
881 }
882 
883 //////////////////////////////////////////////////////////////////////////
884 
885 //建立对象函数
886 extern "C" __declspec(dllexport) void * __cdecl CreateDataBase(const GUID & Guid, DWORD dwInterfaceVer)
887 {
888     //建立对象
889     CDataBase * pDataBase=NULL;
890     try
891     {
892         pDataBase=new CDataBase();
893         if (pDataBase==NULL) throw TEXT("创建失败");
894         void * pObject=pDataBase->QueryInterface(Guid,dwInterfaceVer);
895         if (pObject==NULL) throw TEXT("接口查询失败");
896         return pObject;
897     }
898     catch (...) {}
899 
900     //清理对象
901     SafeDelete(pDataBase);
902     return NULL;
903 }
904 
905 //////////////////////////////////////////////////////////////////////////
DataBaseEngine.cpp

头文件DataBaseEngine.h :

bubuko.com,布布扣
  1 #ifndef DATA_BASE_ENGINE_HEAD_FILE
  2 #define DATA_BASE_ENGINE_HEAD_FILE
  3 
  4 #pragma once
  5 
  6 //组件头文件
  7 #include "ServerKernel.h"
  8 #include "QueueService.h"
  9 
 10 //////////////////////////////////////////////////////////////////////////
 11 
 12 //ADO 错误类
 13 class CADOError : public IADOError
 14 {
 15     //变量定义
 16 protected:
 17     enADOErrorType                    m_enErrorType;                        //错误代号
 18     CString                            m_strErrorDescribe;                    //错误信息
 19 
 20     //函数定义
 21 public:
 22     //构造函数
 23     CADOError();
 24     //析构函数
 25     virtual ~CADOError();
 26 
 27     //基础接口
 28 public:
 29     //释放对象
 30     virtual bool __cdecl Release() { return true; }
 31     //是否有效
 32     virtual bool __cdecl IsValid() { return AfxIsValidAddress(this,sizeof(CADOError))?true:false; }
 33     //接口查询
 34     virtual void * __cdecl QueryInterface(const IID & Guid, DWORD dwQueryVer);
 35 
 36     //功能接口
 37 public:
 38     //错误类型
 39     virtual enADOErrorType __cdecl GetErrorType() { return m_enErrorType; }
 40     //错误描述
 41     virtual LPCTSTR __cdecl GetErrorDescribe() { return m_strErrorDescribe; }
 42 
 43     //功能函数
 44 public:
 45     //设置错误
 46     void SetErrorInfo(enADOErrorType enErrorType, LPCTSTR pszDescribe);
 47 };
 48 
 49 //////////////////////////////////////////////////////////////////////////
 50 
 51 //数据库对象
 52 class CDataBase : public IDataBase
 53 {
 54     //信息变量
 55 protected:
 56     CADOError                        m_ADOError;                            //错误对象
 57     CString                            m_strConnect;                        //连接字符串
 58     CString                            m_strErrorDescribe;                    //错误信息
 59 
 60     //状态变量
 61 protected:
 62     DWORD                            m_dwConnectCount;                    //重试次数
 63     DWORD                            m_dwConnectErrorTime;                //错误时间
 64     const DWORD                        m_dwResumeConnectCount;                //恢复次数
 65     const DWORD                        m_dwResumeConnectTime;                //恢复时间
 66 
 67     //内核变量
 68 protected:
 69     _CommandPtr                        m_DBCommand;                        //命令对象
 70     _RecordsetPtr                    m_DBRecordset;                        //记录集对象
 71     _ConnectionPtr                    m_DBConnection;                        //数据库对象
 72 
 73     //函数定义
 74 public:
 75     //构造函数
 76     CDataBase();
 77     //析构函数
 78     virtual ~CDataBase();
 79 
 80     //基础接口
 81 public:
 82     //释放对象
 83     virtual bool __cdecl Release() { if (IsValid()) delete this; return true; }
 84     //是否有效
 85     virtual bool __cdecl IsValid() { return AfxIsValidAddress(this,sizeof(CDataBase))?true:false; }
 86     //接口查询
 87     virtual void * __cdecl QueryInterface(const IID & Guid, DWORD dwQueryVer);
 88 
 89     //管理接口
 90 public:
 91     //打开连接
 92     virtual bool __cdecl OpenConnection();
 93     //关闭记录
 94     virtual bool __cdecl CloseRecordset();
 95     //关闭连接
 96     virtual bool __cdecl CloseConnection();
 97     //重新连接
 98     virtual bool __cdecl TryConnectAgain(bool bFocusConnect, CComError * pComError);
 99     //设置信息
100     virtual bool __cdecl SetConnectionInfo(LPCTSTR szIP, WORD wPort, LPCTSTR szData, LPCTSTR szName, LPCTSTR szPass);
101 
102     //状态接口
103 public:
104     //是否连接错误
105     virtual bool __cdecl IsConnectError();
106     //是否打开
107     virtual bool __cdecl IsRecordsetOpened();
108 
109     //记录集接口
110 public:
111     //往下移动
112     virtual void __cdecl MoveToNext();
113     //移到开头
114     virtual void __cdecl MoveToFirst();
115     //是否结束
116     virtual bool __cdecl IsEndRecordset();
117     //获取数目
118     virtual long __cdecl GetRecordCount();
119     //获取大小
120     virtual long __cdecl GetActualSize(LPCTSTR pszParamName);
121     //绑定对象
122     virtual bool __cdecl BindToRecordset(CADORecordBinding * pBind);
123 
124     //字段接口
125 public:
126     //获取参数
127     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, BYTE & bValue);
128     //获取参数
129     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, WORD & wValue);
130     //获取参数
131     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, INT & nValue);
132     //获取参数
133     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, LONG & lValue);
134     //获取参数
135     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, DWORD & ulValue);
136     //获取参数
137     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, UINT & ulValue);
138     //获取参数
139     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, DOUBLE & dbValue);
140     //获取参数
141     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, __int64 & llValue);
142     //获取参数
143     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, TCHAR szBuffer[], UINT uSize);
144     //获取参数
145     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, COleDateTime & Time);
146     //获取参数
147     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, bool & bValue);
148 
149     //命令对象接口
150 public:
151     //设置存储过程
152     virtual void __cdecl SetSPName(LPCTSTR pszSpName);
153     //插入参数
154     virtual void __cdecl AddParamter(LPCTSTR pszName, ADOCG::ParameterDirectionEnum Direction, ADOCG::DataTypeEnum Type, long lSize, _variant_t & vtValue);
155     //删除参数
156     virtual void __cdecl ClearAllParameters();
157     //获得参数
158     virtual void __cdecl GetParameterValue(LPCTSTR pszParamName, _variant_t & vtValue);
159     //获取返回数值
160     virtual long __cdecl GetReturnValue();
161 
162     //执行接口
163 public:
164     //执行语句
165     virtual bool __cdecl Execute(LPCTSTR pszCommand);
166     //执行命令
167     virtual bool __cdecl ExecuteCommand(bool bRecordset);
168 
169     //内部函数
170 private:
171     //获取错误
172     LPCTSTR GetComErrorDescribe(CComError & ComError);
173     //设置错误
174     void SetErrorInfo(enADOErrorType enErrorType, LPCTSTR pszDescribe);
175 };
176 
177 //////////////////////////////////////////////////////////////////////////
178 
179 //数据库管理类
180 class CDataBaseEngine : public IDataBaseEngine, public IQueueServiceSink
181 {
182     //内核变量
183 protected:
184     bool                            m_bService;                            //运行标志
185     CQueueService                    m_RequestQueueService;                //队列对象
186     IDataBaseSink                    * m_pIDataBaseSink;                    //通知钩子
187 
188     //函数定义
189 public:
190     //构造函数
191     CDataBaseEngine(void);
192     //析构函数
193     virtual ~CDataBaseEngine(void);
194 
195     //基础接口
196 public:
197     //释放对象
198     virtual bool __cdecl Release() { if (IsValid()) delete this; return true; }
199     //是否有效
200     virtual bool __cdecl IsValid() { return AfxIsValidAddress(this,sizeof(CDataBaseEngine))?true:false; }
201     //接口查询
202     virtual void * __cdecl QueryInterface(const IID & Guid, DWORD dwQueryVer);
203 
204     //服务接口
205 public:
206     //启动服务
207     virtual bool __cdecl StartService();
208     //停止服务
209     virtual bool __cdecl StopService();
210     //注册钩子
211     virtual bool __cdecl SetDataBaseSink(IUnknownEx * pIUnknownEx);
212     //获取接口
213     virtual void * __cdecl GetQueueService(const IID & Guid, DWORD dwQueryVer);
214 
215     //队列接口
216 public:
217     //队列接口
218     virtual void __cdecl OnQueueServiceSink(WORD wIdentifier, void * pBuffer, WORD wDataSize, DWORD dwInsertTime);
219 };
220 
221 //////////////////////////////////////////////////////////////////////////
222 
223 #endif
DataBaseEngine.h

头文件Stdafx.h :

bubuko.com,布布扣
 1 #pragma once
 2 
 3 #ifndef VC_EXTRALEAN
 4 #define VC_EXTRALEAN        // 从 Windows 头中排除极少使用的资料
 5 #endif
 6 
 7 // 如果您必须使用下列所指定的平台之前的平台,则修改下面的定义。
 8 // 有关不同平台的相应值的最新信息,请参考 MSDN。
 9 #ifndef WINVER                // 允许使用特定于 Windows 95 和 Windows NT 4 或更高版本的功能。
10 #define WINVER 0x0500        // 将此更改为针对于 Windows 98 和 Windows 2000 或更高版本的合适的值。
11 #endif
12 
13 #ifndef _WIN32_WINNT        // 允许使用特定于 Windows NT 4 或更高版本的功能。
14 #define _WIN32_WINNT 0x0400    // 将此更改为针对于 Windows 2000 或更高版本的合适的值。
15 #endif                        
16 
17 #ifndef _WIN32_WINDOWS        // 允许使用特定于 Windows 98 或更高版本的功能。
18 #define _WIN32_WINDOWS 0x0410 // 将此更改为针对于 Windows Me 或更高版本的合适的值。
19 #endif
20 
21 #ifndef _WIN32_IE            // 允许使用特定于 IE 4.0 或更高版本的功能。
22 #define _WIN32_IE 0x0400    // 将此更改为针对于 IE 5.0 或更高版本的合适的值。
23 #endif
24 
25 #define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS    // 某些 CString 构造函数将为显式的
26 
27 #include <afxwin.h>         // MFC 核心组件和标准组件
28 #include <afxext.h>         // MFC 扩展
29 
30 #ifndef _AFX_NO_OLE_SUPPORT
31 #include <afxole.h>         // MFC OLE 类
32 #include <afxodlgs.h>       // MFC OLE 对话框类
33 #include <afxdisp.h>        // MFC 自动化类
34 #endif // _AFX_NO_OLE_SUPPORT
35 
36 #ifndef _AFX_NO_DB_SUPPORT
37 #include <afxdb.h>            // MFC ODBC 数据库类
38 #endif // _AFX_NO_DB_SUPPORT
39 
40 #ifndef _AFX_NO_DAO_SUPPORT
41 #include <afxdao.h>            // MFC DAO 数据库类
42 #endif // _AFX_NO_DAO_SUPPORT
43 
44 #include <afxdtctl.h>        // MFC 对 Internet Explorer 4 公共控件的支持
45 #ifndef _AFX_NO_AFXCMN_SUPPORT
46 #include <afxcmn.h>            // MFC 对 Windows 公共控件的支持
47 #endif // _AFX_NO_AFXCMN_SUPPORT
Stdafx.h

头文件EventService.h :

bubuko.com,布布扣
 1 #ifndef EVENT_SERVICE_HEAD_FILE
 2 #define EVENT_SERVICE_HEAD_FILE
 3 
 4 #pragma once
 5 
 6 #include "ServerKernel.h"
 7 
 8 //////////////////////////////////////////////////////////////////////////
 9 
10 //事件服务类
11 class CEventService : public IEventService
12 {
13     //变量定义
14 protected:
15     HWND                            m_hRichEdit;                        //控件句柄
16     CThreadLock                        m_ThreadLock;                        //线程锁
17     bool                            m_bEventService[EVENT_LEVEL_COUNT];    //显示标志
18 
19     //状态变量
20 protected:
21     int                                m_nMaxLineCount;                    //最大行数
22     int                                m_nReserveLineCount;                //保留行数
23 
24     //函数定义
25 public:
26     //构造函数
27     CEventService(void);
28     //析构函数
29     virtual ~CEventService(void);
30 
31     //基础接口
32 public:
33     //释放对象
34     virtual bool __cdecl Release() { if (IsValid()) delete this; return true; }
35     //是否有效
36     virtual bool __cdecl IsValid() { return AfxIsValidAddress(this,sizeof(CEventService))?true:false; }
37     //接口查询
38     virtual void * __cdecl QueryInterface(const IID & Guid, DWORD dwQueryVer);
39 
40     //功能接口
41 public:
42     //设置句柄
43     virtual bool __cdecl SetRichEditHwnd(HWND hRichEdit);
44     //设置级别
45     virtual void __cdecl ConfigEventService(enTraceLevel TraceLevel, bool bShow);
46     //事件通知
47     virtual void __cdecl ShowEventNotify(LPCTSTR pszString, enTraceLevel TraceLevel);
48 };
49 
50 //////////////////////////////////////////////////////////////////////////
51 
52 //事件输出类
53 class CEventTrace
54 {
55     //变量定义
56 private:
57     static IEventService                    * m_pIEventService;            //事件接口
58 
59     //函数定义
60 private:
61     //构造函数
62     CEventTrace() {}
63 
64     //功能函数
65 public:
66     //设置接口
67     static bool SetEventService(IUnknownEx * pIUnknownEx);
68     //获取接口
69     static void * GetEventService(const IID & Guid, DWORD dwQueryVer);
70     //设置级别
71     static void ConfigEventService(enTraceLevel TraceLevel, bool bShow);
72     //事件通知
73     static void ShowEventNotify(LPCTSTR pszString, enTraceLevel TraceLevel);
74 };
75 
76 //////////////////////////////////////////////////////////////////////////
77 
78 #endif
EventService.h

头文件ServerKernel.h:

bubuko.com,布布扣
  1 #ifndef SERVER_KERNEL_HEAD_FILE
  2 #define SERVER_KERNEL_HEAD_FILE
  3 
  4 //////////////////////////////////////////////////////////////////////////
  5 
  6 //系统头文件
  7 #include <ICrsint.h>
  8 #include <WinSock2.h>
  9 
 10 //平台头文件
 11 #include "..\..\Include\模板库\Template.h"
 12 #include "..\..\Include\公共文件\GlobalDef.h"
 13 #include "..\..\Include\组件接口\IUnknownEx.h"
 14 #include "..\..\共享组件\公共服务\ComService.h"
 15 
 16 //////////////////////////////////////////////////////////////////////////
 17 
 18 //ADO 导入库
 19 #import "MSADO15.DLL" rename_namespace("ADOCG") rename("EOF","EndOfFile")
 20 using namespace ADOCG;
 21 
 22 //COM 错误类型
 23 typedef _com_error                    CComError;                            //COM 错误
 24 
 25 //////////////////////////////////////////////////////////////////////////
 26 //公共宏定义
 27 
 28 //模块定义
 29 #ifdef _DEBUG
 30     #define SERVER_KERNEL_DLL_NAME    TEXT("KernelD.dll")            //组件 DLL 名字
 31 #else
 32     #define SERVER_KERNEL_DLL_NAME    TEXT("Kernel.dll")            //组件 DLL 名字
 33 #endif
 34 
 35 //常量宏定义
 36 #define EVENT_LEVEL_COUNT            4                                    //事件等级
 37 #define MAX_QUEUE_PACKET            10240                                //最大队列
 38 #define INDEX_ALL_SOCKET            0xFFFF                                //所有连接
 39 #define TIMER_REPEAT_TIMER            DWORD(-1)                            //重复次数
 40 
 41 //////////////////////////////////////////////////////////////////////////
 42 //枚举定义
 43 
 44 //输出等级
 45 enum enTraceLevel
 46 {
 47     Level_Normal                    =0,                                    //普通消息
 48     Level_Warning                    =1,                                    //警告消息
 49     Level_Exception                    =2,                                    //异常消息
 50     Level_Debug                        =3,                                    //调试消息
 51 };
 52 
 53 //数据库错误代码
 54 enum enADOErrorType
 55 {
 56     ErrorType_Nothing                =0,                                    //没有错误
 57     ErrorType_Connect                =1,                                    //连接错误
 58     ErrorType_Other                    =2,                                    //其他错误
 59 };
 60 
 61 //////////////////////////////////////////////////////////////////////////
 62 //事件定义
 63 
 64 //事件标识
 65 #define EVENT_CONTROL                0x0001                                //控制消息
 66 #define EVENT_TIMER                    0x0002                                //定时器引擎
 67 #define EVENT_DATABASE                0x0003                                //数据库请求
 68 #define EVENT_SOCKET_ACCEPT            0x0004                                //网络应答
 69 #define EVENT_SOCKET_READ            0x0005                                //网络读取
 70 #define EVENT_SOCKET_CLOSE            0x0006                                //网络关闭
 71 
 72 //定时器事件
 73 struct NTY_TimerEvent
 74 {
 75     WORD                            wTimerID;                            //定时器 ID
 76     WPARAM                            wBindParam;                            //绑定参数
 77 };
 78 
 79 //数据库请求事件
 80 struct NTY_DataBaseEvent
 81 {
 82     WORD                            wIndex;                                //对象索引
 83     WORD                            wRoundID;                            //对象标识
 84     WORD                            wRequestID;                            //请求标识
 85 };
 86 
 87 //网络应答事件
 88 struct NTY_SocketAcceptEvent
 89 {
 90     WORD                            wIndex;                                //连接索引
 91     WORD                            wRoundID;                            //连接标识
 92     DWORD                            dwClientIP;                            //连接地址
 93 };
 94 
 95 //网络读取事件
 96 struct NTY_SocketReadEvent
 97 {
 98     WORD                            wIndex;                                //连接索引
 99     WORD                            wRoundID;                            //连接标识
100     WORD                            wDataSize;                            //数据大小
101     CMD_Command                        Command;                            //命令信息
102 };
103 
104 //网络关闭事件
105 struct NTY_SocketCloseEvent
106 {
107     WORD                            wIndex;                                //连接索引
108     WORD                            wRoundID;                            //连接标识
109     DWORD                            dwClientIP;                            //连接地址
110     DWORD                            dwConnectSecond;                    //连接时间
111 };
112 
113 //////////////////////////////////////////////////////////////////////////
114 
115 #define VER_IADOError INTERFACE_VERSION(5,2)
116 static const GUID IID_IADOError={0x66463b5a,0x390c,0x42f9,0x85,0x19,0x13,0x31,0x39,0x36,0xfe,0x8f};
117 
118 //数据库错误接口
119 interface IADOError : public IUnknownEx
120 {
121     //错误描述
122     virtual LPCTSTR __cdecl GetErrorDescribe()=NULL;
123     //错误类型
124     virtual enADOErrorType __cdecl GetErrorType()=NULL;
125 };
126 
127 //////////////////////////////////////////////////////////////////////////
128 
129 #define VER_IDataBase INTERFACE_VERSION(5,2)
130 static const GUID IID_IDataBase={0x9e962173,0x2a9f,0x4ebd,0x8e,0x98,0x40,0xe9,0x96,0x57,0x24,0xfb};
131 
132 //数据库连接接口
133 interface IDataBase : public IUnknownEx
134 {
135     //打开连接
136     virtual bool __cdecl OpenConnection()=NULL;
137     //关闭记录
138     virtual bool __cdecl CloseRecordset()=NULL;
139     //关闭连接
140     virtual bool __cdecl CloseConnection()=NULL;
141     //重新连接
142     virtual bool __cdecl TryConnectAgain(bool bFocusConnect, CComError * pComError)=NULL;
143     //设置信息
144     virtual bool __cdecl SetConnectionInfo(LPCTSTR szIP, WORD wPort, LPCTSTR szData, LPCTSTR szName, LPCTSTR szPass)=NULL;
145     //是否连接错误
146     virtual bool __cdecl IsConnectError()=NULL;
147     //是否打开
148     virtual bool __cdecl IsRecordsetOpened()=NULL;
149     //往下移动
150     virtual void __cdecl MoveToNext()=NULL;
151     //移到开头
152     virtual void __cdecl MoveToFirst()=NULL;
153     //是否结束
154     virtual bool __cdecl IsEndRecordset()=NULL;
155     //获取数目
156     virtual long __cdecl GetRecordCount()=NULL;
157     //获取大小
158     virtual long __cdecl GetActualSize(LPCTSTR pszParamName)=NULL;
159     //绑定对象
160     virtual bool __cdecl BindToRecordset(CADORecordBinding * pBind)=NULL;
161     //获取参数
162     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, BYTE & bValue)=NULL;
163     //获取参数
164     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, WORD & wValue)=NULL;
165     //获取参数
166     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, INT & nValue)=NULL;
167     //获取参数
168     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, LONG & lValue)=NULL;
169     //获取参数
170     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, DWORD & ulValue)=NULL;
171     //获取参数
172     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, UINT & ulValue)=NULL;
173     //获取参数
174     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, DOUBLE & dbValue)=NULL;
175     //获取参数
176     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, __int64 & llValue)=NULL;
177     //获取参数
178     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, TCHAR szBuffer[], UINT uSize)=NULL;
179     //获取参数
180     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, COleDateTime & Time)=NULL;
181     //获取参数
182     virtual bool __cdecl GetFieldValue(LPCTSTR lpFieldName, bool & bValue)=NULL;
183     //设置存储过程
184     virtual void __cdecl SetSPName(LPCTSTR pszSpName)=NULL;
185     //插入参数
186     virtual void __cdecl AddParamter(LPCTSTR pszName, ADOCG::ParameterDirectionEnum Direction, ADOCG::DataTypeEnum Type, long lSize, _variant_t & vtValue)=NULL;
187     //删除参数
188     virtual void __cdecl ClearAllParameters()=NULL;
189     //获得参数
190     virtual void __cdecl GetParameterValue(LPCTSTR pszParamName, _variant_t & vtValue)=NULL;
191     //获取返回数值
192     virtual long __cdecl GetReturnValue()=NULL;
193     //执行语句
194     virtual bool __cdecl Execute(LPCTSTR pszCommand)=NULL;
195     //执行命令
196     virtual bool __cdecl ExecuteCommand(bool bRecordset)=NULL;
197 };
198 
199 //////////////////////////////////////////////////////////////////////////
200 
201 #define VER_IDataBaseSink INTERFACE_VERSION(5,2)
202 static const GUID IID_IDataBaseSink={0x1287cdc2,0xcbda,0x4bb6,0x95,0xeb,0xd9,0xcc,0x6a,0x2b,0xef,0xd3};
203 
204 //数据库钩子接口
205 interface IDataBaseSink : public IUnknownEx
206 {
207     //数据库模块启动
208     virtual bool __cdecl StartService(IUnknownEx * pIUnknownEx)=NULL;
209     //数据库模块关闭
210     virtual bool __cdecl StopService(IUnknownEx * pIUnknownEx)=NULL;
211     //数据操作处理
212     virtual bool __cdecl OnDataBaseRequest(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize)=NULL;
213 };
214 
215 //////////////////////////////////////////////////////////////////////////
216 
217 #define VER_IDataBaseEngine INTERFACE_VERSION(5,2)
218 static const GUID IID_IDataBaseEngine={0x9b00b2a6,0x620e,0x4791,0x97,0xad,0x28,0x32,0x16,0xf1,0x8c,0xdf};
219 
220 //数据库引擎接口
221 interface IDataBaseEngine : public IUnknownEx
222 {
223     //启动服务
224     virtual bool __cdecl StartService()=NULL;
225     //停止服务
226     virtual bool __cdecl StopService()=NULL;
227     //注册钩子
228     virtual bool __cdecl SetDataBaseSink(IUnknownEx * pIUnknownEx)=NULL;
229     //获取接口
230     virtual void * __cdecl GetQueueService(const IID & Guid, DWORD dwQueryVer)=NULL;
231 };
232 
233 //////////////////////////////////////////////////////////////////////////
234 
235 #define VER_IQueueServiceSink INTERFACE_VERSION(5,2)
236 static const GUID IID_IQueueServiceSink={0x88b5bf59,0x3a98,0x43b1,0xac,0x85,0xf1,0x17,0x5b,0x29,0x69,0x40};
237 
238 //数据队列类钩子接口
239 interface IQueueServiceSink : public IUnknownEx
240 {
241     //通知回调函数
242     virtual void __cdecl OnQueueServiceSink(WORD wIdentifier, void * pBuffer, WORD wDataSize, DWORD dwInsertTime)=NULL;
243 };
244 
245 //////////////////////////////////////////////////////////////////////////
246 
247 #define VER_IQueueService INTERFACE_VERSION(5,2)
248 static const GUID IID_IQueueService={0xcc5310b5,0x3709,0x40aa,0x85,0x24,0xd6,0xc5,0x87,0xb0,0x32,0x22};
249 
250 //数据队列接口
251 interface IQueueService : public IUnknownEx
252 {
253     //加入数据
254     virtual bool __cdecl AddToQueue(WORD wIdentifier, void * const pBuffer, WORD wDataSize)=NULL;
255 };
256 
257 //////////////////////////////////////////////////////////////////////////
258 
259 #define VER_IQueueServiceEngine INTERFACE_VERSION(5,2)
260 static const GUID IID_IQueueServiceEngine={0xba2c602e,0x7f5a,0x40ad,0xb7,0xa5,0x7d,0x1c,0x2a,0x8f,0xee,0x78};
261 
262 //队列类引擎接口
263 interface IQueueServiceEngine : public IUnknownEx
264 {
265     //开始服务
266     virtual bool __cdecl StartService()=NULL;
267     //停止服务
268     virtual bool __cdecl StopService()=NULL;
269     //设置接口
270     virtual bool __cdecl SetQueueServiceSink(IUnknownEx * pIUnknownEx)=NULL;
271     //负荷信息
272     virtual bool __cdecl GetBurthenInfo(tagBurthenInfo & BurthenInfo)=NULL;
273 };
274 
275 //////////////////////////////////////////////////////////////////////////
276 
277 #define VER_IEventService INTERFACE_VERSION(5,2)
278 static const GUID IID_IEventService={0x729d0499,0xad36,0x49d5,0x8d,0x46,0xfd,0xd,0x78,0x82,0xa6,0x37};
279 
280 //服务引擎接口
281 interface IEventService : public IUnknownEx
282 {
283     //设置句柄
284     virtual bool __cdecl SetRichEditHwnd(HWND hRichEdit)=NULL;
285     //设置级别
286     virtual void __cdecl ConfigEventService(enTraceLevel TraceLevel, bool bShow)=NULL;
287     //事件通知
288     virtual void __cdecl ShowEventNotify(LPCTSTR pszString, enTraceLevel TraceLevel)=NULL;
289 };
290 
291 //////////////////////////////////////////////////////////////////////////
292 
293 #define VER_ITimerEngine INTERFACE_VERSION(5,2)
294 static const GUID IID_ITimerEngine={0x4a9b0421,0x1224,0x4e5e,0xa5,0x4f,0xb1,0x61,0x6e,0x62,0xdb,0x98};
295 
296 //定时器引擎接口
297 interface ITimerEngine : public IUnknownEx
298 {
299     //设置定时器
300     virtual bool __cdecl SetTimer(WORD wTimerID, DWORD dwElapse, DWORD dwRepeat, WPARAM wParam)=NULL; 
301     //删除定时器
302     virtual bool __cdecl KillTimer(WORD wTimerID)=NULL;
303     //删除定时器
304     virtual bool __cdecl KillAllTimer()=NULL;
305 };
306 
307 //////////////////////////////////////////////////////////////////////////
308 
309 #define VER_ITimerEngineManager INTERFACE_VERSION(5,2)
310 static const GUID IID_ITimerEngineManager={0xcdbfa840,0xdc45,0x41f7,0xb6,0x3c,0xad,0x83,0x75,0x98,0xc6,0x3e};
311 
312 //定时器引擎接口
313 interface ITimerEngineManager : public IUnknownEx
314 {
315     //开始服务
316     virtual bool __cdecl StartService()=NULL;
317     //停止服务
318     virtual bool __cdecl StopService()=NULL;
319     //设置接口
320     virtual bool __cdecl SetTimerEngineSink(IUnknownEx * pIUnknownEx)=NULL;
321 };
322 
323 //////////////////////////////////////////////////////////////////////////
324 
325 #define VER_ITCPSocketEngine INTERFACE_VERSION(5,2)
326 static const GUID IID_ITCPSocketEngine={0x9979ea68,0x5ee7,0x4c15,0xa4,0xdf,0x9f,0xe3,0x85,0x26,0x13,0xbb};
327 
328 //TCP SOCKET 引擎接口
329 interface ITCPSocketEngine : public IUnknownEx
330 {
331     //检测连接
332     virtual bool __cdecl DetectSocket()=NULL;
333     //发送函数
334     virtual bool __cdecl SendData(WORD wIndex, WORD wRoundID, WORD wMainCmdID, WORD wSubCmdID)=NULL;
335     //发送函数
336     virtual bool __cdecl SendData(WORD wIndex, WORD wRoundID, WORD wMainCmdID, WORD wSubCmdID, void * pData, WORD wDataSize)=NULL;
337     //批量发送
338     virtual bool __cdecl SendDataBatch(WORD wMainCmdID, WORD wSubCmdID, void * pData, WORD wDataSize)=NULL;
339     //关闭连接
340     virtual bool __cdecl CloseSocket(WORD wIndex, WORD wRoundID)=NULL;
341     //关闭连接
342     virtual bool __cdecl ShutDownSocket(WORD wIndex, WORD wRoundID)=NULL;
343     //允许群发
344     virtual bool __cdecl AllowBatchSend(WORD wIndex, WORD wRoundID, bool bAllow)=NULL;
345 };
346 
347 //////////////////////////////////////////////////////////////////////////
348 
349 #define VER_ITCPSocketEngineManager INTERFACE_VERSION(5,2)
350 static const GUID IID_ITCPSocketEngineManager={0xf91b246f,0x3c97,0x4445,0xb3,0xeb,0xb9,0x42,0x3b,0x68,0x1b,0xed};
351 
352 //TCP SOCKET 引擎管理接口
353 interface ITCPSocketEngineManager : public IUnknownEx
354 {
355     //设置接口
356     virtual bool __cdecl SetSocketEngineSink(IUnknownEx * pIUnknownEx)=NULL;
357     //设置端口
358     virtual bool __cdecl SetServicePort(WORD wListenPort)=NULL;
359     //设置数目
360     virtual bool __cdecl SetMaxSocketItem(WORD wMaxSocketItem)=NULL;
361     //启动服务
362     virtual bool __cdecl StartService()=NULL;
363     //停止服务
364     virtual bool __cdecl StopService()=NULL;
365 };
366 
367 //////////////////////////////////////////////////////////////////////////
368 
369 #define VER_IAttemperEngineSink INTERFACE_VERSION(5,2)
370 static const GUID IID_IAttemperEngineSink={0x82d2c5,0x4e6f,0x4031,0xae,0xd4,0x6f,0xee,0x5a,0x17,0x1b,0x8a};
371 
372 //调度模块钩子接口
373 interface IAttemperEngineSink : public IUnknownEx
374 {
375     //管理接口
376 public:
377     //调度模块启动
378     virtual bool __cdecl StartService(IUnknownEx * pIUnknownEx)=NULL;
379     //调度模块关闭
380     virtual bool __cdecl StopService(IUnknownEx * pIUnknownEx)=NULL;
381     //事件处理接口
382     virtual bool __cdecl OnAttemperEvent(WORD wIdentifier, void * pBuffer, WORD wDataSize, DWORD dwInsertTime)=NULL;
383 
384     //事件接口
385 public:
386     //定时器事件
387     virtual bool __cdecl OnEventTimer(WORD wTimerID, WPARAM wBindParam)=NULL;
388     //数据库事件
389     virtual bool __cdecl OnEventDataBase(void * pDataBuffer, WORD wDataSize, NTY_DataBaseEvent * pDataBaseEvent)=NULL;
390     //网络应答事件
391     virtual bool __cdecl OnEventSocketAccept(NTY_SocketAcceptEvent * pSocketAcceptEvent)=NULL;
392     //网络读取事件
393     virtual bool __cdecl OnEventSocketRead(CMD_Command Command, void * pDataBuffer, WORD wDataSize, NTY_SocketReadEvent * pSocketReadEvent)=NULL;
394     //网络关闭事件
395     virtual bool __cdecl OnEventSocketClose(NTY_SocketCloseEvent * pSocketCloseEvent)=NULL;
396 };
397 
398 //////////////////////////////////////////////////////////////////////////
399 
400 #define VER_IAttemperEngine INTERFACE_VERSION(5,2)
401 static const GUID IID_IAttemperEngine={0x967b3e64,0x69af,0x434a,0xb8,0x6c,0x67,0x9b,0x72,0xbb,0x2e,0xe};
402 
403 //调度引擎接口
404 interface IAttemperEngine : public IUnknownEx
405 {
406     //管理接口
407 public:
408     //启动服务
409     virtual bool __cdecl StartService()=NULL;
410     //停止服务
411     virtual bool __cdecl StopService()=NULL;
412     //设置网络
413     virtual bool __cdecl SetSocketEngine(IUnknownEx * pIUnknownEx)=NULL;
414     //设置钩子
415     virtual bool __cdecl SetAttemperEngineSink(IUnknownEx * pIUnknownEx)=NULL;
416     //获取接口
417     virtual void * __cdecl GetQueueService(const IID & Guid, DWORD dwQueryVer)=NULL;
418 };
419 
420 //////////////////////////////////////////////////////////////////////////
421 
422 #define VER_IServiceEngine INTERFACE_VERSION(5,2)
423 static const GUID IID_IServiceEngine={0x74284fc0,0xc587,0x4c21,0x9b,0x7c,0x16,0x76,0x27,0x1a,0x7b,0xd5};
424 
425 //服务引擎接口
426 interface IServiceEngine : public IUnknownEx
427 {
428     //服务接口
429 public:
430     //启动服务
431     virtual bool __cdecl StartService()=NULL;
432     //停止服务
433     virtual bool __cdecl StopService()=NULL;
434 
435     //配置接口
436 public:
437     //设置事件
438     virtual bool __cdecl SetEventService(IUnknownEx * pIUnknownEx)=NULL;
439     //设置钩子
440     virtual bool __cdecl SetDataBaseSink(IUnknownEx * pIUnknownEx)=NULL;
441     //设置钩子
442     virtual bool __cdecl SetAttemperEngineSink(IUnknownEx * pIUnknownEx)=NULL;
443     //注册钩子
444     virtual bool __cdecl RegisterAsynchronismEngineSink(IUnknownEx * pIUnknownEx)=NULL;
445     //设置网络引擎接口
446     virtual bool __cdecl InitServiceEngine(WORD wListenPort, WORD wMaxSocketItem)=NULL;
447 
448     //服务查询
449 public:
450     //获取定时器接口
451     virtual void * __cdecl GetTimerEngine(const IID & Guid, DWORD dwQueryVer)=NULL;
452     //获取数据库引擎接口
453     virtual void * __cdecl GetDataBaseEngine(const IID & Guid, DWORD dwQueryVer)=NULL;
454     //获取调度引擎接口
455     virtual void * __cdecl GetAttemperEngine(const IID & Guid, DWORD dwQueryVer)=NULL;
456     //获取网络引擎接口
457     virtual void * __cdecl GetTCPSocketEngine(const IID & Guid, DWORD dwQueryVer)=NULL;
458     //获取异步引擎接口
459     virtual void * __cdecl GetAsynchronismEngine(const IID & Guid, DWORD dwQueryVer)=NULL;
460     //获取接口
461     virtual void * __cdecl GetDataBaseQueueService(const IID & Guid, DWORD dwQueryVer)=NULL;
462     //获取接口
463     virtual void * __cdecl GetAttemperQueueService(const IID & Guid, DWORD dwQueryVer)=NULL;
464 
465     //功能接口
466 public:
467     //服务状态
468     virtual bool __cdecl IsService()=NULL;
469     //外部控制
470     virtual bool __cdecl ControlService(void * pBuffer, WORD wDataSize)=NULL;
471 };
472 
473 //////////////////////////////////////////////////////////////////////////
474 
475 #define VER_IAsynchronismEngine INTERFACE_VERSION(5,2)
476 static const GUID IID_IAsynchronismEngine={0x3728c1a5,0x37a9,0x4ace,0x8e,0x31,0xd9,0xb1,0xce,0x63,0xd9,0x88};
477 
478 //异步引擎接口
479 interface IAsynchronismEngine : public IUnknownEx
480 {
481     //管理接口
482 public:
483     //启动服务
484     virtual bool __cdecl StartService()=NULL;
485     //停止服务
486     virtual bool __cdecl StopService()=NULL;
487     //插入请求
488     virtual bool __cdecl InsertRequest(WORD wRequestID, void * const pBuffer, WORD wDataSize, IUnknownEx * pIUnknownEx)=NULL;
489 
490     //功能接口
491 public:
492     //注册钩子
493     virtual bool __cdecl RegisterAsynchronismEngineSink(IUnknownEx * pIUnknownEx)=NULL;
494     //取消注册
495     virtual bool __cdecl UnRegisterAsynchronismEngineSink(IUnknownEx * pIUnknownEx)=NULL;
496 };
497 
498 //////////////////////////////////////////////////////////////////////////
499 
500 #define VER_IAsynchronismEngineSink INTERFACE_VERSION(5,2)
501 static const GUID IID_IAsynchronismEngineSink={0x6898f671,0x5c4b,0x4555,0x8c,0x82,0x49,0xc4,0xf3,0x2a,0xeb,0x4d};
502 
503 //异步引擎钩子接口
504 interface IAsynchronismEngineSink : public IUnknownEx
505 {
506     //启动事件
507     virtual bool __cdecl OnAsynchronismEngineStart()=NULL;
508     //停止事件
509     virtual bool __cdecl OnAsynchronismEngineStop()=NULL;
510     //异步请求
511     virtual bool __cdecl OnAsynchronismRequest(WORD wRequestID, void * pBuffer, WORD wDataSize)=NULL;
512 };
513 
514 //////////////////////////////////////////////////////////////////////////
515 
516 //导出组件文件
517 #include "QueueServiceEvent.h"
518 #include "ServerKernelHelper.h"
519 
520 //////////////////////////////////////////////////////////////////////////
521 
522 #endif
ServerKernel.h

头文件QueueService.h:

bubuko.com,布布扣
  1 #ifndef QUEUE_SERVICE_HEAD_FILE
  2 #define QUEUE_SERVICE_HEAD_FILE
  3 
  4 #include "ServerKernel.h"
  5 
  6 #pragma once
  7 
  8 //////////////////////////////////////////////////////////////////////////
  9 
 10 //队列线程类
 11 class CQueueServiceThread : public CServiceThread
 12 {
 13     //友员定义
 14     friend class CQueueService;
 15 
 16     //配置定义
 17 protected:
 18     HANDLE                            m_hCompletionPort;                    //完成端口
 19 
 20     //辅助变量
 21 private:
 22     BYTE                            m_cbBuffer[MAX_QUEUE_PACKET];        //接收缓冲
 23 
 24     //函数定义
 25 protected:
 26     //构造函数
 27     CQueueServiceThread(void);
 28     //析构函数
 29     virtual ~CQueueServiceThread(void);
 30 
 31     //功能函数
 32 public:
 33     //配置函数
 34     bool InitThread(HANDLE hCompletionPort);
 35     //取消配置
 36     bool UnInitThread();
 37 
 38     //重载函数
 39 private:
 40     //运行函数
 41     virtual bool RepetitionRun();
 42 };
 43 
 44 //////////////////////////////////////////////////////////////////////////
 45 
 46 //数据队列类
 47 class CQueueService : public IQueueServiceEngine, public IQueueService 
 48 {
 49     friend class CQueueServiceThread;
 50 
 51     //变量定义
 52 protected:
 53     bool                            m_bService;                            //服务标志
 54     HANDLE                            m_hCompletionPort;                    //完成端口
 55     IQueueServiceSink                * m_pIQueueServiceSink;                //回调接口
 56 
 57     //组件变量
 58 protected:
 59     CThreadLock                        m_ThreadLock;                        //线程锁
 60     CDataStorage                    m_DataStorage;                        //数据存储
 61     CQueueServiceThread                m_QueueServiceThread;                //队列线程
 62 
 63     //函数定义
 64 public:
 65     //构造函数
 66     CQueueService(void);
 67     //析构函数
 68     virtual ~CQueueService(void);
 69 
 70     //基础接口
 71 public:
 72     //释放对象
 73     virtual bool __cdecl Release() { if (IsValid()) delete this; return true; }
 74     //是否有效
 75     virtual bool __cdecl IsValid() { return AfxIsValidAddress(this,sizeof(CQueueService))?true:false; }
 76     //接口查询
 77     virtual void * __cdecl QueryInterface(const IID & Guid, DWORD dwQueryVer);
 78 
 79     //队列接口
 80 public:
 81     //加入数据
 82     virtual bool __cdecl AddToQueue(WORD wIdentifier, void * const pBuffer, WORD wDataSize);
 83 
 84     //管理接口
 85 public:
 86     //开始服务
 87     virtual bool __cdecl StartService();
 88     //停止服务
 89     virtual bool __cdecl StopService();
 90     //设置接口
 91     virtual bool __cdecl SetQueueServiceSink(IUnknownEx * pIUnknownEx);
 92     //负荷信息
 93     virtual bool __cdecl GetBurthenInfo(tagBurthenInfo & BurthenInfo);
 94 
 95     //辅助函数
 96 private:
 97     //提取数据
 98     bool GetData(tagDataHead & DataHead, void * pBuffer, WORD wBufferSize);
 99     //数据消息
100     void OnQueueServiceThread(const tagDataHead & DataHead, void * pBuffer, WORD wDataSize);
101 };
102 
103 //////////////////////////////////////////////////////////////////////////
104 
105 #endif
QueueService.h

头文件Template.h :

bubuko.com,布布扣
 1 #ifndef TEMPLATE_HEAD_FILE
 2 #define TEMPLATE_HEAD_FILE
 3 
 4 /////////////////////////////////////////////////////////////////////////////////////////
 5 
 6 //计算数组维数
 7 #define CountArray(Array) (sizeof(Array)/sizeof(Array[0]))
 8 
 9 //计算字符长度
10 #define CountString(String) ((UINT)((lstrlen(String)+1)*sizeof(TCHAR)))
11 
12 //安全删除指针
13 #define  SafeDelete(pData)    { try { delete pData; } catch (...) { } pData=NULL; } 
14 
15 //安全删除指针
16 #define  SafeDeleteArray(pData)    { try { delete [] pData; } catch (...) { } pData=NULL; } 
17 
18 /////////////////////////////////////////////////////////////////////////////////////////
19 
20 //模板头文件
21 #include "Array.h"
22 #include "Modelu.h"
23 #include "Factory.h"
24 
25 /////////////////////////////////////////////////////////////////////////////////////////
26 
27 #endif
Template.h

头文件GlobalDef.h :

bubuko.com,布布扣
  1 #ifndef GLOBAL_DEF_HEAD_FILE
  2 #define GLOBAL_DEF_HEAD_FILE
  3 
  4 #pragma once
  5 
  6 /////////////////////////////////////////////////////////////////////////////////////////
  7 //常量定义
  8 
  9 const TCHAR    szProductName[]=TEXT("");                                        //产品名字
 10 const TCHAR szSystemRegKey[]=TEXT("LEGame");                                //注册主键
 11 //const TCHAR szStationPage[]=TEXT("http://61.176.192.182");                    //游戏主页
 12 //const TCHAR szStationPage[]=TEXT("http://127.0.0.1");                    //游戏主页
 13 //屏幕位置
 14 #define LESS_SCREEN_X                950                                        //最小宽度
 15 #define LESS_SCREEN_Y                682                                     //最小高度
 16 
 17 /////////////////////////////////////////////////////////////////////////////////////////
 18 //宏定义
 19 
 20 #define MAX_CHAIR                        100                                    //最大游戏者
 21 #define MAX_ANDROID                        256                                    //最大机器
 22 #define MAX_CHAIR_NORMAL                8                                    //最大游戏者
 23 #define INVALID_GAME_KINDID             ((int)-1)                           //无效游戏KindID
 24 
 25 #define MAX_CHAT_LEN                    512                                    //聊天长度
 26 #define INVALID_TABLE                    ((WORD)(-1))                        //无效桌子号
 27 #define INVALID_CHAIR                    ((WORD)(-1))                        //无效椅子号
 28 
 29 #ifdef DEBUG
 30 #define MAIN_DLG_CLASSNAME                TEXT("LEGameD")                        //窗口注册名
 31 #else
 32 #define MAIN_DLG_CLASSNAME                TEXT("LEGame")                        //窗口注册名
 33 #endif
 34 
 35 //机器信息定义
 36 //#define SERVER_INFO                        TEXT("e7949286f9269ae2c8c2e05bd1cabaa5")//服务端信息
 37 #define SERVER_NUMBER                    (WORD(2))                            //服务器数量
 38 
 39 //端口定义
 40 #define PORT_VIDEO_SERVER                7600                                //视频服务器
 41 #define PORT_LOGON_SERVER                8800                                //登陆服务器
 42 #define PORT_CENTER_SERVER                8810                                //中心服务器
 43 
 44 //网络数据定义
 45 #define SOCKET_VER                        187                                    //数据包版本
 46 #define SOCKET_PACKAGE                    2046                                //最大网络包
 47 #define SOCKET_BUFFER                    (sizeof(CMD_Head)+SOCKET_PACKAGE+2*sizeof(DWORD))
 48 
 49 //分配模式
 50 #define DISTRIBUTE_MODE_NONE            0                                    //自由分配
 51 #define DISTRIBUTE_MODE_RAND            1                                    //随机分配
 52 #define DISTRIBUTE_MODE_PLAN            2                                    //定位分配
 53 
 54 /////////////////////////////////////////////////////////////////////////////////////////
 55 
 56 //数据包结构信息
 57 struct CMD_Info
 58 {
 59     WORD                                wDataSize;                            //数据大小
 60     BYTE                                cbCheckCode;                        //效验字段
 61     BYTE                                cbMessageVer;                        //版本标识
 62 };
 63 
 64 //数据包命令信息
 65 struct CMD_Command
 66 {
 67     WORD                                wMainCmdID;                            //主命令码
 68     WORD                                wSubCmdID;                            //子命令码
 69 };
 70 
 71 //数据包传递包头
 72 struct CMD_Head
 73 {
 74     CMD_Info                            CmdInfo;                            //基础结构
 75     CMD_Command                            CommandInfo;                        //命令信息
 76 };
 77 
 78 //网络数据包缓冲
 79 struct CMD_Buffer
 80 {
 81     CMD_Head                            Head;                                //数据包头
 82     BYTE                                cbBuffer[SOCKET_PACKAGE];            //数据缓冲
 83 };
 84 
 85 //内核命令码
 86 #define MDM_KN_COMMAND                    0                                    //内核命令
 87 #define SUB_KN_DETECT_SOCKET            1                                    //检测命令
 88 
 89 //检测结构信息
 90 struct CMD_KN_DetectSocket
 91 {
 92     DWORD                                dwSendTickCount;                    //发送时间
 93     DWORD                                dwRecvTickCount;                    //接收时间
 94 };
 95 
 96 /////////////////////////////////////////////////////////////////////////////////////////
 97 
 98 //IPC 数据定义
 99 #define IPC_VER                            0x0009                                //IPC 版本
100 #define IPC_IDENTIFIER                    0x0001                                //标识号码
101 #define IPC_PACKAGE                        4096                                //最大 IPC 包
102 #define IPC_BUFFER                        (sizeof(IPC_Head)+IPC_PACKAGE)        //缓冲长度
103 
104 //IPC 数据包头
105 struct IPC_Head
106 {
107     WORD                                wVersion;                            //IPC 版本
108     WORD                                wDataSize;                            //数据大小
109     WORD                                wMainCmdID;                            //主命令码
110     WORD                                wSubCmdID;                            //子命令码
111 };
112 
113 //IPC 缓冲结构
114 struct IPC_Buffer
115 {
116     IPC_Head                            Head;                                //数据包头
117     BYTE                                cbBuffer[IPC_PACKAGE];                //数据缓冲
118 };
119 
120 //////////////////////////////////////////////////////////////////////////
121 
122 //长度宏定义
123 #define TYPE_LEN                        32                                    //种类长度
124 #define KIND_LEN                        32                                    //类型长度
125 #define STATION_LEN                        32                                    //站点长度
126 #define SERVER_LEN                        12                                    //房间长度
127 #define MODULE_LEN                        32                                    //进程长度
128 #define PASSWORD_LEN                    2                                    //密码长度
129 
130 //性别定义
131 #define GENDER_NULL                        0                                    //未知性别
132 #define GENDER_BOY                        1                                    //男性性别
133 #define GENDER_GIRL                        2                                    //女性性别
134 
135 //游戏类型
136 #define GAME_GENRE_SCORE                0x0001                                //点值类型
137 #define GAME_GENRE_GOLD                    0x0002                                //金币类型
138 #define GAME_GENRE_MATCH                0x0004                                //比赛类型
139 #define GAME_GENRE_EDUCATE                0x0008                                //训练类型
140 
141 //游戏类型定义(同城模式)
142 #define NORMAL_MODE                        0                                    //正常模式
143 #define RECREATION_MODE                    1                                    //同城模式
144 
145 //游戏类型结构
146 struct tagGameType
147 {
148     WORD                                wSortID;                            //排序号码
149     WORD                                wTypeID;                            //种类号码
150     TCHAR                                szTypeName[TYPE_LEN];                //种类名字
151 };
152 
153 //游戏名称结构
154 struct tagGameKind
155 {
156     WORD                                wSortID;                            //排序号码
157     WORD                                wTypeID;                            //类型号码
158     WORD                                wKindID;                            //名称号码
159     DWORD                                dwMaxVersion;                        //最新版本
160     DWORD                                dwOnLineCount;                        //在线数目
161     TCHAR                                szKindName[KIND_LEN];                //游戏名字
162     TCHAR                                szProcessName[MODULE_LEN];            //进程名字(不包含后缀名)
163 };
164 
165 //游戏进程结构
166 struct tagGameProcess
167 {
168     WORD                                wSortID;                            //排序号码
169     WORD                                wTypeID;                            //类型号码
170     WORD                                wKindID;                            //名称号码
171     WORD                                wServerPort;                        //房间端口
172     DWORD                                dwServerAddr;                        //房间地址
173     DWORD                                dwMaxVersion;                        //最新版本
174     DWORD                                dwOnLineCount;                        //在线数目
175     TCHAR                                szKindName[KIND_LEN];                //游戏名字
176     TCHAR                                szProcessName[MODULE_LEN];            //进程名字(不包含后缀名)
177 };
178 
179 //游戏站点结构
180 struct tagGameStation
181 {
182     WORD                                wSortID;                            //排序号码
183     WORD                                wKindID;                            //名称号码
184     WORD                                wJoinID;                            //挂接号码
185     WORD                                wStationID;                            //站点号码
186     TCHAR                                szStationName[STATION_LEN];            //站点名称
187 };
188 
189 //游戏房间列表结构
190 struct tagGameServer
191 {
192     WORD                                wSortID;                            //排序号码
193     WORD                                wKindID;                            //名称号码
194     WORD                                wServerID;                            //房间号码
195     WORD                                wStationID;                            //站点号码
196     WORD                                wServerPort;                        //房间端口
197     DWORD                                dwServerAddr;                        //房间地址
198     DWORD                                dwOnLineCount;                        //在线人数
199     DWORD                                dwOnLineCountBase;                    //在线人数
200     DWORD                                dwMaxCount;                            //最大人数
201     LONG                                lCellScore;                            //单位积分
202     LONG                                lLessScore;                            //最低积分
203     LONG                                lHighScore;                            //最高积分
204     LONG                                lGuoDi;                                //锅底
205     LONG                                lReductScore;                        //进房间扣金币
206     WORD                                wServerType;                        //房间类型
207     BYTE                                cbGameMode;                            //游戏模式
208     TCHAR                                szServerName[MODULE_LEN];            //房间名称
209     WORD                                wKeepDecimalPoint;                    //保留小数位数
210     TCHAR                                szRoomPassword[PASSWORD_LEN];        //房间密码
211 };
212 
213 //////////////////////////////////////////////////////////////////////////
214 
215 //用户状态定义
216 #define US_NULL                            0x00                                //没有状态
217 #define US_FREE                            0x01                                //站立状态
218 #define US_SIT                            0x02                                //坐下状态
219 #define US_READY                        0x03                                //同意状态
220 #define US_LOOKON                        0x04                                //旁观状态
221 #define US_PLAY                            0x05                                //游戏状态
222 #define US_OFFLINE                        0x06                                //断线状态
223 
224 //长度宏定义
225 #define NAME_LEN                        32                                    //名字长度
226 #define PASS_LEN                        33                                    //密码长度
227 #define EMAIL_LEN                        32                                    //邮箱长度
228 #define GROUP_LEN                        32                                    //社团长度
229 #define DATETIME_LEN                    16                                    //时间长度
230 #define COMPUTER_ID_LEN                    33                                    //机器序列
231 #define DETAILS_LEN                        33                                    //记录描述
232 #define UNDER_WRITE_LEN                    32                                    //个性签名
233 #define CLIENT_INFO_LEN                    200                                    //客户端信息
234 
235 //用户积分信息
236 struct tagUserScore
237 {
238     LONG                                lScore;                                //用户分数
239     LONG                                lGold;                                //用户金币
240     //LONG                                lPaiCoin;                            //用户金币
241     LONG                                lExperience;                        //用户经验
242     LONG                                lWinCount;                            //胜利盘数
243     LONG                                lLostCount;                            //失败盘数
244     LONG                                lDrawCount;                            //和局盘数
245     LONG                                lFleeCount;                            //断线数目
246 };
247 
248 //用户状态信息
249 struct tagUserStatus
250 {
251     WORD                                wTableID;                            //桌子号码
252     WORD                                wChairID;                            //椅子位置
253     WORD                                wNetDelay;                            //网络延时
254     BYTE                                cbUserStatus;                        //用户状态
255 };
256 
257 ////用户基本信息结构
258 //struct tagUserInfoHead
259 //{
260 //    //用户属性
261 //    WORD                                wFaceID;                            //头像索引
262 //    BYTE                                cbMember;                            //会员等级
263 //    DWORD                                dwUserID;                            //用户 I D
264 //    DWORD                                dwGameID;                            //游戏 I D
265 //    DWORD                                dwGroupID;                            //社团索引
266 //    DWORD                                dwUserRight;                        //用户等级
267 //    DWORD                                dwMasterRight;                        //管理权限
268 //
269 //    //用户属性
270 //    BYTE                                cbGender;                            //用户性别
271 //    BYTE                                cbMemberOrder;                        //会员等级
272 //    BYTE                                cbMasterOrder;                        //管理等级
273 //
274 //    //用户状态
275 //    WORD                                wTableID;                            //桌子号码
276 //    WORD                                wChairID;                            //椅子位置
277 //    WORD                                wNetDelay;                            //网络延时
278 //    BYTE                                cbUserStatus;                        //用户状态
279 //    BOOL                                bVipMode;                            //VIP模式
280 //    //用户积分
281 //    tagUserScore                        UserScoreInfo;                        //积分信息
282 //    TCHAR                                stLognoIP[COMPUTER_ID_LEN];           //IP登陆地址
283 //};
284 
285 //用户信息结构
286 struct tagUserData
287 {
288     //用户属性
289     WORD                                wFaceID;                            //头像索引
290     DWORD                                dwUserID;                            //用户 I D
291     DWORD                                dwGroupID;                            //社团索引
292     DWORD                                dwGameID;                            //用户 I D
293     DWORD                                dwUserRight;                        //用户等级
294     DWORD                                dwMasterRight;                        //管理权限
295     TCHAR                                szAccounts[NAME_LEN];                //用户名字
296     TCHAR                                szNickname[NAME_LEN];                //用户名字
297     TCHAR                                szGroupName[GROUP_LEN];                //社团名字
298     TCHAR                                szUnderWrite[UNDER_WRITE_LEN];        //个性签名
299 
300     //用户属性
301     BYTE                                cbGender;                            //用户性别
302     BYTE                                cbMemberOrder;                        //会员等级
303     BYTE                                cbMasterOrder;                        //管理等级
304     BOOL                                bVipMode;                            //是否为VIP用户
305 
306     BOOL                                bAIFlag;                            //机器人用户标识
307 
308     //其他信息
309     BYTE                                cbCompanion;                        //用户关系
310     CHAR                                swLognoIP[COMPUTER_ID_LEN];            //IP登陆地址
311 
312     
313     tagUserScore                        UserScoreInfo;                        //积分信息
314     tagUserStatus                        UserStatus;
315 };
316 
317 typedef tagUserData tagUserInfoHead;
318 //////////////////////////////////////////////////////////////////////////
319 
320 //本机信息结构
321 struct tagLocalInfo
322 {
323     TCHAR                                szLoaclInfo[1024];                    //本机信息
324 };
325 
326 //机器序列号结构
327 struct tagClientSerial
328 {
329     DWORD                                dwSystemVer;                        //系统版本
330     DWORD                                dwComputerID[3];                    //机器序列
331 };
332 
333 //配置缓冲结构
334 struct tagOptionBuffer
335 {
336     BYTE                                cbBufferLen;                        //数据长度
337     BYTE                                cbOptionBuf[32];                    //设置缓冲
338 };
339 
340 /////////////////////////////////////////////////////////////////////////////////////////
341 
342 #endif
GlobalDef.h

头文件IUnknownEx.h :

bubuko.com,布布扣
  1 #ifndef IUNKNOWN_EX_HEAD_FILE
  2 #define IUNKNOWN_EX_HEAD_FILE
  3 
  4 //////////////////////////////////////////////////////////////////////////
  5 
  6 //产品版本号
  7 #define PRODUCT_VER                3
  8 
  9 //版本定义
 10 #define INTERFACE_VERSION(cbMainVer,cbSubVer)                                 11         (DWORD)(                                                             12         (((BYTE)(PRODUCT_VER))<<24)+                                         13         (((BYTE)(cbMainVer))<<16)+                                             14         ((BYTE)(cbSubVer)<<8))
 15 
 16 //获取产品版本
 17 inline BYTE GetProductVer(DWORD dwVersion)
 18 {
 19     BYTE * cbVersion=(BYTE *)&dwVersion;
 20     return cbVersion[3];
 21 }
 22 
 23 //获取主版本
 24 inline BYTE GetMainVer(DWORD dwVersion)
 25 {
 26     BYTE * cbVersion=(BYTE *)&dwVersion;
 27     return cbVersion[2];
 28 }
 29 
 30 //获取子版本
 31 inline BYTE GetSubVer(DWORD dwVersion)
 32 {
 33     BYTE * cbVersion=(BYTE *)&dwVersion;
 34     return cbVersion[1];
 35 }
 36 
 37 //获取编译版本
 38 inline BYTE GetBulidVer(DWORD dwVersion)
 39 {
 40     BYTE * cbVersion=(BYTE *)&dwVersion;
 41     return cbVersion[0];
 42 }
 43 
 44 //版本对比函数
 45 inline bool InterfaceVersionCheck(DWORD dwQueryVer, DWORD dwInterfaceVer)
 46 {
 47     if (GetProductVer(dwQueryVer)!=GetProductVer(dwInterfaceVer)) return false;
 48     if (GetMainVer(dwQueryVer)!=GetMainVer(dwInterfaceVer)) return false;
 49     if (GetSubVer(dwQueryVer)>GetSubVer(dwInterfaceVer)) return false;
 50     return true;
 51 };
 52 
 53 //////////////////////////////////////////////////////////////////////////
 54 
 55 //接口定义
 56 #define STD_METHOD(TYPE,METHOD) virtual TYPE __cdecl METHOD
 57 
 58 //接口组件创建函数说明
 59 typedef void * (__cdecl ModuleCreateFunc)(const GUID & Gudi, DWORD dwInterfaceVer);
 60 
 61 //////////////////////////////////////////////////////////////////////////
 62 
 63 #define VER_IUnknownEx INTERFACE_VERSION(5,2)
 64 static const GUID IID_IUnknownEx={0x92d87e91,0x5a5b,0x4a45,0x8c,0xfd,0x38,0x2f,0xe6,0xb3,0x2b,0xb};
 65 
 66 //基础接口
 67 interface IUnknownEx
 68 {
 69     //是否有效
 70     virtual bool __cdecl IsValid()=NULL;
 71     //释放对象
 72     virtual bool __cdecl Release()=NULL;
 73     //接口查询
 74     virtual void * __cdecl QueryInterface(const IID & Guid, DWORD dwQueryVer)=NULL;
 75 };
 76 
 77 //////////////////////////////////////////////////////////////////////////
 78 
 79 //接口查询宏
 80 #define QUERYINTERFACE(Interface,Guid,dwQueryVer)                                         81     if ((Guid==IID_##Interface)&&(InterfaceVersionCheck(dwQueryVer,VER_##Interface)))     82         return static_cast<Interface *>(this);                                            
 83 
 84 #define QUERYINTERFACE_IUNKNOWNEX(BaseInterface,Guid,dwQueryVer)                         85     if ((Guid==IID_IUnknownEx)&&(InterfaceVersionCheck(dwQueryVer,VER_IUnknownEx)))         86         return static_cast<IUnknownEx *>(static_cast<BaseInterface *>(this));            
 87 
 88 //获取接口宏
 89 #define GET_MYSELF_INTERFACE(Interface)                                                     90     ((Interface *)QueryInterface(IID_##Interface,VER_##Interface))
 91 
 92 #define GET_OBJECT_INTERFACE(Object,Interface)                                             93     ((Interface *)Object.QueryInterface(IID_##Interface,VER_##Interface))
 94 
 95 #define GET_OBJECTPTR_INTERFACE(pObject,Interface)                                         96     ((pObject==NULL)?NULL:((Interface *)pObject->QueryInterface(IID_##Interface,VER_##Interface)))
 97 
 98 //////////////////////////////////////////////////////////////////////////
 99 
100 #endif
IUnknownEx.h

头文件ComService.h :

bubuko.com,布布扣
 1 #ifndef COM_SERVICE_HEAD_FILE
 2 #define COM_SERVICE_HEAD_FILE
 3 
 4 //////////////////////////////////////////////////////////////////////////
 5 
 6 //系统头文件
 7 #include "AfxHtml.h"
 8 
 9 //平台头文件
10 #include "..\..\Include\模板库\Template.h"
11 
12 //////////////////////////////////////////////////////////////////////////
13 
14 //导出类头文件
15 #include "WinFileInfo.h"
16 #include "DataStorage.h"
17 #include "ServiceThread.h"
18 #include "JiaMi.h"
19 #include "Markup.h"
20 
21 //////////////////////////////////////////////////////////////////////////
22 
23 #endif
ComService.h

头文件QueueServiceEvent.h:

bubuko.com,布布扣
  1 #ifndef QUEUE_SERVICE_EVENT_HEAD_FILE
  2 #define QUEUE_SERVICE_EVENT_HEAD_FILE
  3 
  4 #pragma once
  5 
  6 #include "ServerKernel.h"
  7 
  8 //////////////////////////////////////////////////////////////////////////
  9 
 10 //数据队列事件
 11 class CQueueServiceEvent
 12 {
 13     //变量定义
 14 public:
 15     CThreadLock                        m_BufferLock;                        //同步锁定
 16     IQueueService *                    m_pIQueueService;                    //队列接口
 17     BYTE                            m_cbBuffer[MAX_QUEUE_PACKET];        //接收缓冲
 18 
 19     //函数定义
 20 public:
 21     //构造函数
 22     CQueueServiceEvent() { m_pIQueueService=NULL; }
 23     //析构函数
 24     virtual ~CQueueServiceEvent() {}
 25 
 26     //管理函数
 27 public:
 28     //设置接口
 29     bool SetQueueService(IUnknownEx * pIUnknownEx)
 30     {
 31         ASSERT(pIUnknownEx!=NULL);
 32         m_pIQueueService=GET_OBJECTPTR_INTERFACE(pIUnknownEx,IQueueService);
 33         ASSERT(m_pIQueueService!=NULL);
 34         return (m_pIQueueService!=NULL);
 35     }
 36     //获取接口
 37     void * GetQueueService(const IID & Guid, DWORD dwQueryVer)
 38     {
 39         if (m_pIQueueService==NULL) return NULL;
 40         return m_pIQueueService->QueryInterface(Guid,dwQueryVer);
 41     }
 42     //是否有效
 43     bool IsValid() { return (m_pIQueueService!=NULL); }
 44 
 45     //通知函数
 46 public:
 47     //定时器事件
 48     bool PostTimerEvent(WORD wTimerID, WPARAM wBindParam)
 49     {
 50         //效验参数
 51         ASSERT(m_pIQueueService!=NULL);
 52         if (m_pIQueueService==NULL) return false;
 53 
 54         //缓冲锁定
 55         CThreadLockHandle BufferLockHandle(&m_BufferLock);
 56 
 57         //投递消息
 58         NTY_TimerEvent * pTimerEvent=(NTY_TimerEvent *)m_cbBuffer;
 59         pTimerEvent->wTimerID=wTimerID;
 60         pTimerEvent->wBindParam=wBindParam;
 61         m_pIQueueService->AddToQueue(EVENT_TIMER,m_cbBuffer,sizeof(NTY_TimerEvent));
 62 
 63         return true;
 64     }
 65     //数据库事件
 66     bool PostDataBaseEvent(WORD wRequestID, WORD wIndex, WORD wRoundID, const void * pDataBuffer, WORD wDataSize)
 67     {
 68         //效验参数
 69         ASSERT(m_pIQueueService!=NULL);
 70         ASSERT((wDataSize+sizeof(NTY_DataBaseEvent))<=MAX_QUEUE_PACKET);
 71         if (m_pIQueueService==NULL) return false;
 72         if ((wDataSize+sizeof(NTY_DataBaseEvent))>MAX_QUEUE_PACKET) return false;
 73 
 74         //缓冲锁定
 75         CThreadLockHandle BufferLockHandle(&m_BufferLock);
 76 
 77         //投递消息
 78         NTY_DataBaseEvent * pDataBaseEvent=(NTY_DataBaseEvent *)m_cbBuffer;
 79         pDataBaseEvent->wIndex=wIndex;
 80         pDataBaseEvent->wRequestID=wRequestID;
 81         pDataBaseEvent->wRoundID=wRoundID;
 82         if (wDataSize>0)
 83         {
 84             ASSERT(pDataBuffer!=NULL);
 85             CopyMemory(m_cbBuffer+sizeof(NTY_DataBaseEvent),pDataBuffer,wDataSize);
 86         }
 87         m_pIQueueService->AddToQueue(EVENT_DATABASE,m_cbBuffer,sizeof(NTY_DataBaseEvent)+wDataSize);
 88 
 89         return true;
 90     }
 91     //网络应答事件
 92     bool PostSocketAcceptEvent(WORD wIndex, WORD wRoundID, DWORD dwClientIP)
 93     {
 94         //效验参数
 95         ASSERT(m_pIQueueService!=NULL);
 96         if (m_pIQueueService==NULL) return false;
 97 
 98         //缓冲锁定
 99         CThreadLockHandle BufferLockHandle(&m_BufferLock);
100 
101         //投递消息
102         NTY_SocketAcceptEvent * pSocketAcceptEvent=(NTY_SocketAcceptEvent *)m_cbBuffer;
103         pSocketAcceptEvent->wIndex=wIndex;
104         pSocketAcceptEvent->wRoundID=wRoundID;
105         pSocketAcceptEvent->dwClientIP=dwClientIP;
106         m_pIQueueService->AddToQueue(EVENT_SOCKET_ACCEPT,m_cbBuffer,sizeof(NTY_SocketAcceptEvent));
107 
108         return true;
109     }
110     //网络读取事件
111     bool PostSocketReadEvent(WORD wIndex, WORD wRoundID, CMD_Command Command, const void * pDataBuffer, WORD wDataSize)
112     {
113         //效验参数
114         ASSERT(m_pIQueueService!=NULL);
115         ASSERT((wDataSize+sizeof(NTY_SocketReadEvent))<=MAX_QUEUE_PACKET);
116         if (m_pIQueueService==NULL) return false;
117         if ((wDataSize+sizeof(NTY_SocketReadEvent))>MAX_QUEUE_PACKET) return false;
118 
119         //缓冲锁定
120         CThreadLockHandle BufferLockHandle(&m_BufferLock);
121 
122         //投递消息
123         NTY_SocketReadEvent * pSocketReadEvent=(NTY_SocketReadEvent *)m_cbBuffer;
124         pSocketReadEvent->wIndex=wIndex;
125         pSocketReadEvent->wRoundID=wRoundID;
126         pSocketReadEvent->Command=Command;
127         pSocketReadEvent->wDataSize=wDataSize;
128         if (wDataSize>0)
129         {
130             ASSERT(pDataBuffer!=NULL);
131             CopyMemory(m_cbBuffer+sizeof(NTY_SocketReadEvent),pDataBuffer,wDataSize);
132         }
133         m_pIQueueService->AddToQueue(EVENT_SOCKET_READ,m_cbBuffer,sizeof(NTY_SocketReadEvent)+wDataSize);
134 
135         return false;
136     }
137     //网络关闭事件
138     bool PostSocketCloseEvent(WORD wIndex, WORD wRoundID, DWORD dwClientIP, DWORD dwConnectSecond)
139     {
140         //效验参数
141         ASSERT(m_pIQueueService!=NULL);
142         if (m_pIQueueService==NULL) return false;
143 
144         //缓冲锁定
145         CThreadLockHandle BufferLockHandle(&m_BufferLock);
146 
147         //投递消息
148         NTY_SocketCloseEvent * pSocketCloseEvent=(NTY_SocketCloseEvent *)m_cbBuffer;
149         pSocketCloseEvent->wIndex=wIndex;
150         pSocketCloseEvent->wRoundID=wRoundID;
151         pSocketCloseEvent->dwClientIP=dwClientIP;
152         pSocketCloseEvent->dwConnectSecond=dwConnectSecond;
153         m_pIQueueService->AddToQueue(EVENT_SOCKET_CLOSE,m_cbBuffer,sizeof(NTY_SocketCloseEvent));
154 
155         return true;
156     }
157 };
158 
159 //////////////////////////////////////////////////////////////////////////
160 
161 #endif
QueueServiceEvent.h

头文件ServerKernelHelper.h:

bubuko.com,布布扣
  1 #ifndef SERVER_KERNEL_HELPER_HEAD_FILE
  2 #define SERVER_KERNEL_HELPER_HEAD_FILE
  3 
  4 #pragma once
  5 
  6 #include "ServerKernel.h"
  7 
  8 //////////////////////////////////////////////////////////////////////////
  9 
 10 //事件服务辅助类
 11 class CEventServiceHelper : public CTempldateHelper<IEventService>
 12 {
 13     //函数定义
 14 public:
 15     //构造函数
 16     CEventServiceHelper(void) : CTempldateHelper<IEventService>(IID_IEventService,
 17         VER_IEventService,SERVER_KERNEL_DLL_NAME,TEXT("CreateKernelEvent")) { }
 18 };
 19 
 20 //////////////////////////////////////////////////////////////////////////
 21 
 22 //数据库引擎辅助类
 23 class CDataBaseHelper : public CTempldateHelper<IDataBase>
 24 {
 25     //函数定义
 26 public:
 27     //构造函数
 28     CDataBaseHelper(void) : CTempldateHelper<IDataBase>(IID_IDataBase,
 29         VER_IDataBase,SERVER_KERNEL_DLL_NAME,TEXT("CreateDataBase")) { }
 30 };
 31 
 32 //////////////////////////////////////////////////////////////////////////
 33 
 34 //服务引擎辅助类
 35 class CServiceEngineHelper : public CTempldateHelper<IServiceEngine>
 36 {
 37     //函数定义
 38 public:
 39     //构造函数
 40     CServiceEngineHelper(void) : CTempldateHelper<IServiceEngine>(IID_IServiceEngine,
 41         VER_IServiceEngine,SERVER_KERNEL_DLL_NAME,TEXT("CreateServiceEngine")) { }
 42 };
 43 
 44 //////////////////////////////////////////////////////////////////////////
 45 
 46 //自动清理参数辅助类
 47 class CAutoCleanParameters
 48 {
 49     //变量定义
 50 private:
 51     CDataBaseHelper                        & m_DataBaseHelper;                //数据库对象
 52 
 53     //函数定义
 54 public:
 55     //构造函数
 56     CAutoCleanParameters(CDataBaseHelper & DataBaseHelper) : m_DataBaseHelper(DataBaseHelper) { }
 57     //析构函数    
 58     virtual ~CAutoCleanParameters()
 59     {
 60         if (m_DataBaseHelper.IsValid()) m_DataBaseHelper->ClearAllParameters();
 61     }
 62 };
 63 
 64 //自动关闭记录集辅助类
 65 class CAutoCloseRecord
 66 {
 67     //变量定义
 68 private:
 69     CDataBaseHelper                        & m_DataBaseHelper;                //数据库对象
 70 
 71     //函数定义
 72 public:
 73     //构造函数
 74     CAutoCloseRecord(CDataBaseHelper & DataBaseHelper) : m_DataBaseHelper(DataBaseHelper) { }
 75     //析构函数    
 76     virtual ~CAutoCloseRecord()
 77     {
 78         if (m_DataBaseHelper.IsValid()) m_DataBaseHelper->CloseRecordset();
 79     }
 80 };
 81 
 82 //断开数据库连接辅助类
 83 class CAutoCloseDataBase
 84 {
 85     //变量定义
 86 private:
 87     CDataBaseHelper                        & m_DataBaseHelper;                //数据库对象
 88 
 89     //函数定义
 90 public:
 91     //构造函数
 92     CAutoCloseDataBase(CDataBaseHelper & DataBaseHelper) : m_DataBaseHelper(DataBaseHelper) { }
 93     //析构函数    
 94     virtual ~CAutoCloseDataBase()
 95     {
 96         if (m_DataBaseHelper.IsValid()) m_DataBaseHelper->CloseConnection();
 97     }
 98 };
 99 
100 //////////////////////////////////////////////////////////////////////////
101 
102 #endif
ServerKernelHelper.h

 

 

调用的例子:

DataBaseSink.cpp:

bubuko.com,布布扣
  1 #include "StdAfx.h"
  2 #include "Afxinet.h"
  3 #include "DataBaseSink.h"
  4 
  5 //////////////////////////////////////////////////////////////////////////
  6 
  7 //构造函数
  8 CDataBaseSink::CDataBaseSink()
  9 {
 10     //设置变量
 11     m_pIEventService=NULL;
 12     m_pGameUserDBInfo=NULL;
 13     m_pGameScoreDBInfo=NULL;
 14     m_pGameServiceAttrib=NULL;
 15     m_pGameServiceOption=NULL;
 16     //临时IP地址
 17     tempIP.Add("1.1.2.1") ;
 18 
 19 
 20     return;
 21 }
 22 
 23 //析构函数
 24 CDataBaseSink::~CDataBaseSink()
 25 {
 26 }
 27 
 28 //接口查询
 29 void * __cdecl CDataBaseSink::QueryInterface(const IID & Guid, DWORD dwQueryVer)
 30 {
 31     QUERYINTERFACE(IDataBaseSink,Guid,dwQueryVer);
 32     QUERYINTERFACE_IUNKNOWNEX(IDataBaseSink,Guid,dwQueryVer);
 33     return NULL;
 34 }
 35 
 36 //调度模块启动
 37 bool __cdecl CDataBaseSink::StartService(IUnknownEx * pIUnknownEx)
 38 {
 39     //效验参数
 40     ASSERT(m_pGameUserDBInfo!=NULL);
 41     ASSERT(m_pGameScoreDBInfo!=NULL);
 42     ASSERT(m_pGameServiceOption!=NULL);
 43     ASSERT(m_AttemperEvent.IsValid()==true);
 44 
 45     //创建实例
 46     if ((m_GameUserDB.GetInterface()==NULL)&&(m_GameUserDB.CreateInstance()==false))
 47     {
 48         m_pIEventService->ShowEventNotify(TEXT("用户数据库对象创建失败"),Level_Exception);
 49         return false;
 50     }
 51 
 52     //创建实例
 53     if ((m_GameScoreDB.GetInterface()==NULL)&&(m_GameScoreDB.CreateInstance()==false))
 54     {
 55         m_pIEventService->ShowEventNotify(TEXT("游戏数据库对象创建失败"),Level_Exception);
 56         return false;
 57     }
 58 
 59     try
 60     {
 61         //变量定义
 62         BYTE * pcbAddr=NULL;
 63         TCHAR szDataBaseAddr[16]=TEXT("");
 64 
 65         //连接用户数据库
 66         pcbAddr=(BYTE *)&m_pGameUserDBInfo->dwDataBaseAddr;
 67         _snprintf(szDataBaseAddr,sizeof(szDataBaseAddr),TEXT("%d.%d.%d.%d"),pcbAddr[0],pcbAddr[1],pcbAddr[2],pcbAddr[3]);
 68         m_GameUserDB->SetConnectionInfo(szDataBaseAddr,m_pGameUserDBInfo->wDataBasePort,m_pGameUserDBInfo->szDataBaseName,
 69             m_pGameUserDBInfo->szDataBaseUser,m_pGameUserDBInfo->szDataBasePass);
 70         m_GameUserDB->OpenConnection();
 71 
 72         //连接游戏数据库
 73         pcbAddr=(BYTE *)&m_pGameScoreDBInfo->dwDataBaseAddr;
 74         _snprintf(szDataBaseAddr,sizeof(szDataBaseAddr),TEXT("%d.%d.%d.%d"),pcbAddr[0],pcbAddr[1],pcbAddr[2],pcbAddr[3]);
 75         m_GameScoreDB->SetConnectionInfo(szDataBaseAddr,m_pGameScoreDBInfo->wDataBasePort,m_pGameScoreDBInfo->szDataBaseName,
 76             m_pGameScoreDBInfo->szDataBaseUser,m_pGameScoreDBInfo->szDataBasePass);
 77         m_GameScoreDB->OpenConnection();
 78 
 79         SPResetChanged(m_pGameServiceOption->wKindID, m_pGameServiceOption->wServerID);
 80         SPResetAbnormity(m_pGameServiceOption->wKindID, m_pGameServiceOption->wServerID);
 81 
 82         return true;
 83     }
 84     catch (IADOError * pIADOError)
 85     {
 86         m_pIEventService->ShowEventNotify(pIADOError->GetErrorDescribe(),Level_Exception);
 87     }
 88 
 89     return false;
 90 }
 91 
 92 //调度模块关闭
 93 bool __cdecl CDataBaseSink::StopService(IUnknownEx * pIUnknownEx)
 94 {
 95     try
 96     {
 97         //关闭连接
 98         if (m_GameUserDB.GetInterface()) m_GameUserDB->CloseConnection();
 99         if (m_GameScoreDB.GetInterface()) m_GameScoreDB->CloseConnection();
100 
101         return true;
102     }
103     catch (IADOError * pIADOError)
104     {
105         m_pIEventService->ShowEventNotify(pIADOError->GetErrorDescribe(),Level_Exception);
106     }
107 
108     return false;
109 }
110 
111 //数据操作处理
112 bool __cdecl CDataBaseSink::OnDataBaseRequest(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize)
113 {
114     switch (DataBaseEvent.wRequestID)
115     {
116     case DBR_GR_LOGON_BY_USERID:        //I D 登录
117         {
118             return OnRequestLogon(DataBaseEvent,pDataBuffer,wDataSize);
119         }
120     case DBR_GR_WRITE_GAME_SCORE:        //写分操作
121         {
122             return OnRequestWriteUserScore(DataBaseEvent,pDataBuffer,wDataSize);
123         }
124     case DBR_GR_LEAVE_GAME_SERVER:        //离开房间
125         {
126             return OnRequestLeaveGameServer(DataBaseEvent,pDataBuffer,wDataSize);
127         }
128     case DBR_GR_LIMIT_ACCOUNTS:            //禁用帐号
129         {
130             return OnRequestLimitAccounts(DataBaseEvent,pDataBuffer,wDataSize);
131         }
132     case DBR_GR_SET_USER_RIGHT:            //设置权限
133         {
134             return OnRequestSetUserRight(DataBaseEvent,pDataBuffer,wDataSize);
135         }
136     case DBR_GR_GAME_DETAILS_RECORD:      //记录游戏
137         {
138             return OnRequestRecordGameDetails(DataBaseEvent,pDataBuffer,wDataSize);
139         }
140     case DBR_GR_LOAD_ANDROID:        //装载机器人
141         {
142             return OnRequestReadAIUser(DataBaseEvent,pDataBuffer,wDataSize);
143         }
144     case DBR_GR_UNLOCK_BY_USERID:        //I D 解锁用户
145         {
146             return OnRequestUnLockUser(DataBaseEvent,pDataBuffer,wDataSize);
147         }
148     }
149 
150     return false;
151 }
152 
153 //设置事件
154 bool CDataBaseSink::SetEventService(IUnknownEx * pIUnknownEx)
155 {
156     ASSERT(pIUnknownEx!=NULL);
157     m_pIEventService=GET_OBJECTPTR_INTERFACE(pIUnknownEx,IEventService);
158     ASSERT(m_pIEventService!=NULL);
159     return (m_pIEventService!=NULL);
160 }
161 
162 //配置函数
163 bool CDataBaseSink::InitDataBaseSink(tagDataBaseSinkParameter * pDataBaseSinkParameter, IUnknownEx * pIUnknownEx)
164 {
165     //效验参数
166     ASSERT(pIUnknownEx!=NULL);
167     ASSERT(pDataBaseSinkParameter!=NULL);
168 
169     //设置变量
170     m_pGameUserDBInfo=pDataBaseSinkParameter->pGameUserDBInfo;
171     m_pGameScoreDBInfo=pDataBaseSinkParameter->pGameScoreDBInfo;
172     m_pGameServiceAttrib=pDataBaseSinkParameter->pGameServiceAttrib;
173     m_pGameServiceOption=pDataBaseSinkParameter->pGameServiceOption;
174 
175     //查询接口
176     IServiceEngine * pIServiceEngine=(IServiceEngine *)pIUnknownEx->QueryInterface(IID_IServiceEngine,VER_IServiceEngine);
177     ASSERT(pIServiceEngine!=NULL);
178     if (pIServiceEngine==NULL) throw TEXT("服务引擎接口查询失败");
179 
180     //获取逻辑引擎
181     IAttemperEngine * pIAttemperEngine=(IAttemperEngine *)pIServiceEngine->GetAttemperEngine(IID_IAttemperEngine,VER_IAttemperEngine);
182     ASSERT(pIAttemperEngine!=NULL);
183     if (pIAttemperEngine==NULL) throw TEXT("调度引擎接口查询失败");
184 
185     //设置通知组件
186     IUnknownEx * pIQueueService=(IUnknownEx *)pIAttemperEngine->GetQueueService(IID_IQueueService,VER_IQueueService);
187     if (m_AttemperEvent.SetQueueService(pIQueueService)==false) throw TEXT("逻辑引擎通知接口设置失败");
188 
189     return true;
190 }
191 
192 //登录请求处理
193 bool CDataBaseSink::OnRequestLogon(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize)
194 {
195     //参数效验
196     ASSERT(DataBaseEvent.wRequestID==DBR_GR_LOGON_BY_USERID);
197     if (DataBaseEvent.wRequestID!=DBR_GR_LOGON_BY_USERID) return false;
198 
199     //效验参数
200     ASSERT(wDataSize==sizeof(DBR_GR_LogonByUserID));
201     if (wDataSize!=sizeof(DBR_GR_LogonByUserID)) return false;
202 
203     //登陆处理
204     try
205     {
206         //执行查询
207         DBR_GR_LogonByUserID * pLogonByUserID=(DBR_GR_LogonByUserID *)pDataBuffer;
208         LONG lReturnValue=SPLogonByUserID(pLogonByUserID->dwUserID,pLogonByUserID->szPassWord,pLogonByUserID->dwClientIP,pLogonByUserID->szComputerID);
209 
210         //登录失败
211         if (lReturnValue!=0L)
212         {
213             DBR_GR_LogonError LogonError;
214             LogonError.lErrorCode=lReturnValue;
215             m_GameScoreDB->GetFieldValue(TEXT("ErrorDescribe"),LogonError.szErrorDescribe,sizeof(LogonError.szErrorDescribe));
216             m_AttemperEvent.PostDataBaseEvent(DBR_GR_LOGON_ERROR,DataBaseEvent.wIndex,DataBaseEvent.wRoundID,&LogonError,sizeof(LogonError));
217             m_GameScoreDB->CloseRecordset();
218             return true;
219         }
220 
221         //变量定义
222         DBR_GR_LogonSuccess LogonSuccess;
223         memset(&LogonSuccess,0,sizeof(LogonSuccess));
224 
225         //读取用户信息
226         m_GameScoreDB->GetFieldValue(TEXT("UserID"),LogonSuccess.dwUserID);
227         m_GameScoreDB->GetFieldValue(TEXT("GameID"),LogonSuccess.dwGameID);
228         m_GameScoreDB->GetFieldValue(TEXT("FaceID"),LogonSuccess.wFaceID);
229         m_GameScoreDB->GetFieldValue(TEXT("GroupID"),LogonSuccess.dwGroupID);
230         m_GameScoreDB->GetFieldValue(TEXT("UserRight"),LogonSuccess.dwUserRight);
231         m_GameScoreDB->GetFieldValue(TEXT("MasterRight"),LogonSuccess.dwMasterRight);
232         m_GameScoreDB->GetFieldValue(TEXT("Accounts"),LogonSuccess.szAccounts,sizeof(LogonSuccess.szAccounts));
233         m_GameScoreDB->GetFieldValue(TEXT("Nickname"),LogonSuccess.szNickname,sizeof(LogonSuccess.szNickname));
234         m_GameScoreDB->GetFieldValue(TEXT("GroupName"),LogonSuccess.szGroupName,sizeof(LogonSuccess.szGroupName));
235         m_GameScoreDB->GetFieldValue(TEXT("UnderWrite"),LogonSuccess.szUnderWrite,sizeof(LogonSuccess.szUnderWrite));
236 
237         //用户属性
238         m_GameScoreDB->GetFieldValue(TEXT("Gender"),LogonSuccess.cbGender);
239         m_GameScoreDB->GetFieldValue(TEXT("MemberOrder"),LogonSuccess.cbMemberOrder);
240         m_GameScoreDB->GetFieldValue(TEXT("MasterOrder"),LogonSuccess.cbMasterOrder);
241         m_GameScoreDB->GetFieldValue(TEXT("Vip"),LogonSuccess.bVip);
242 
243         //读取游戏信息
244         m_GameScoreDB->GetFieldValue(TEXT("Experience"),LogonSuccess.lExperience);
245         m_GameScoreDB->GetFieldValue(TEXT("Score"),LogonSuccess.lScore);
246         m_GameScoreDB->GetFieldValue(TEXT("Gold"),LogonSuccess.lGold);
247         m_GameScoreDB->GetFieldValue(TEXT("PaiCoin"),LogonSuccess.lPaiCoin);
248         m_GameScoreDB->GetFieldValue(TEXT("WinCount"),LogonSuccess.lWinCount);
249         m_GameScoreDB->GetFieldValue(TEXT("LostCount"),LogonSuccess.lLostCount);
250         m_GameScoreDB->GetFieldValue(TEXT("DrawCount"),LogonSuccess.lDrawCount);
251         m_GameScoreDB->GetFieldValue(TEXT("FleeCount"),LogonSuccess.lFleeCount);
252 
253         //附加信息
254         LogonSuccess.bAIFlage = FALSE;
255         CopyMemory(LogonSuccess.szPassWord,pLogonByUserID->szPassWord,sizeof(LogonSuccess.szPassWord));
256 
257         //转化地址
258         TCHAR szClientIP[16]=TEXT("");
259         BYTE * pClientIP=(BYTE *)&pLogonByUserID->dwClientIP;
260         _snprintf(szClientIP,sizeof(szClientIP),TEXT("%d.%d.%d.%d"),pClientIP[0],pClientIP[1],pClientIP[2],pClientIP[3]);
261 
262         CopyMemory(LogonSuccess.szLognoIP,szClientIP,sizeof(szClientIP));
263 
264 
265         //投递调度通知
266         m_AttemperEvent.PostDataBaseEvent(DBR_GR_LOGON_SUCCESS,DataBaseEvent.wIndex,DataBaseEvent.wRoundID,
267             &LogonSuccess,sizeof(LogonSuccess));
268     }
269     catch (IADOError * pIADOError)
270     {
271         //输出错误
272         if (m_pIEventService!=NULL) m_pIEventService->ShowEventNotify(pIADOError->GetErrorDescribe(),Level_Exception);
273 
274         //操作失败
275         DBR_GR_LogonError LogonError;
276         LogonError.lErrorCode=-1;
277         lstrcpyn(LogonError.szErrorDescribe,TEXT("由于数据库操作异常,请您稍后重试或选择另一游戏服务器!"),sizeof(LogonError.szErrorDescribe));
278         m_AttemperEvent.PostDataBaseEvent(DBR_GR_LOGON_ERROR,DataBaseEvent.wIndex,DataBaseEvent.wRoundID,
279             &LogonError,sizeof(LogonError));
280     }
281 
282     //关闭记录集
283     m_GameScoreDB->CloseRecordset();
284 
285     return true;
286 }
287 
288 //写分请求
289 bool CDataBaseSink::OnRequestWriteUserScore(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize)
290 {
291     try
292     {
293         //效验参数
294         ASSERT(wDataSize==sizeof(DBR_GR_WriteUserScore));
295         if (wDataSize!=sizeof(DBR_GR_WriteUserScore)) return false;
296 
297         //执行查询
298         DBR_GR_WriteUserScore * pWriteUserScore=(DBR_GR_WriteUserScore *)pDataBuffer;
299         SPWriteUserScore(pWriteUserScore->dwUserID,pWriteUserScore->dwPlayTimeCount,pWriteUserScore->dwOnlineTimeCount,
300             pWriteUserScore->dwClientIP,pWriteUserScore->lRevenue,pWriteUserScore->ScoreModifyInfo);
301     }
302     catch (IADOError * pIADOError)
303     {
304         //输出错误
305         if (m_pIEventService!=NULL) m_pIEventService->ShowEventNotify(pIADOError->GetErrorDescribe(),Level_Exception);
306     }
307 
308     return true;
309 }
310 
311 //离开房间
312 bool CDataBaseSink::OnRequestLeaveGameServer(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize)
313 {
314     try
315     {
316         //效验参数
317         ASSERT(wDataSize==sizeof(DBR_GR_LeaveGameServer));
318         if (wDataSize!=sizeof(DBR_GR_LeaveGameServer)) return false;
319 
320         //执行查询
321         DBR_GR_LeaveGameServer * pLeaveGameServer=(DBR_GR_LeaveGameServer *)pDataBuffer;
322         SPLeaveGameServer(pLeaveGameServer->dwUserID,pLeaveGameServer->dwPlayTimeCount,pLeaveGameServer->dwOnlineTimeCount,
323             pLeaveGameServer->dwClientIP,pLeaveGameServer->lRevenue,pLeaveGameServer->ScoreModifyInfo);
324     }
325     catch (IADOError * pIADOError)
326     {
327         //输出错误
328         if (m_pIEventService!=NULL) m_pIEventService->ShowEventNotify(pIADOError->GetErrorDescribe(),Level_Exception);
329     }
330 
331     return true;
332 }
333 
334 //禁用帐户
335 bool CDataBaseSink::OnRequestLimitAccounts(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize)
336 {
337     try
338     {
339         //效验参数
340         ASSERT(wDataSize==sizeof(DBR_GR_LimitAccounts));
341         if (wDataSize!=sizeof(DBR_GR_LimitAccounts)) return false;
342 
343         //执行查询
344         DBR_GR_LimitAccounts * pLimitAccounts=(DBR_GR_LimitAccounts *)pDataBuffer;
345         SPCongealAccounts(pLimitAccounts->dwUserID);
346 
347         return true;
348     }
349     catch (IADOError * pIADOError)
350     {
351         //输出错误
352         if (m_pIEventService!=NULL) m_pIEventService->ShowEventNotify(pIADOError->GetErrorDescribe(),Level_Exception);
353     }
354 
355     return true;
356 }
357 
358 //设置权限
359 bool CDataBaseSink::OnRequestSetUserRight(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize)
360 {
361     try
362     {
363         //效验参数
364         ASSERT(wDataSize==sizeof(DBR_GR_SetUserRight));
365         if (wDataSize!=sizeof(DBR_GR_SetUserRight)) return false;
366 
367         //执行查询
368         DBR_GR_SetUserRight * pSetUserRight=(DBR_GR_SetUserRight *)pDataBuffer;
369 
370         //游戏权限
371         if (pSetUserRight->cbGame==TRUE) 
372         {
373             SPSetUserGameRight(pSetUserRight->dwUserID,pSetUserRight->dwUserRight,pSetUserRight->dwMasterUserID,pSetUserRight->dwMasterClientIP);
374         }
375 
376         //帐号权限
377         if (pSetUserRight->cbAccounts==TRUE) 
378         {
379             SPSetUserAccountsRight(pSetUserRight->dwUserID,pSetUserRight->dwUserRight,pSetUserRight->dwMasterUserID,pSetUserRight->dwMasterClientIP);
380         }
381 
382         return true;
383     }
384     catch (IADOError * pIADOError)
385     {
386         //输出错误
387         if (m_pIEventService!=NULL) m_pIEventService->ShowEventNotify(pIADOError->GetErrorDescribe(),Level_Exception);
388     }
389 
390     return true;
391 }
392 
393 //记录游戏
394 bool CDataBaseSink::OnRequestRecordGameDetails(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize)
395 {
396     //效验参数
397     ASSERT(wDataSize==sizeof(tagRecordGameDetails));
398     if (wDataSize!=sizeof(tagRecordGameDetails)) return false;
399 
400     //执行查询
401     tagRecordGameDetails * pRecordGame=(tagRecordGameDetails *)pDataBuffer;
402     _variant_t var = 0;
403 
404     //执行存储过程
405     m_GameScoreDB->ClearAllParameters();
406     m_GameScoreDB->SetSPName("GSP_GR_RecordGameDetails");
407     m_GameScoreDB->AddParamter(TEXT("RETURN_VALUE"),adParamReturnValue,adInteger,sizeof(long),var);
408     var = pRecordGame->dwUserID;
409     m_GameScoreDB->AddParamter(TEXT("@UserID"),adParamInput,adInteger,sizeof(long),var);
410     var = pRecordGame->dwKindID;
411     m_GameScoreDB->AddParamter(TEXT("@KindID"),adParamInput,adInteger,sizeof(long),var);
412     COleDateTime dtStart((time_t)pRecordGame->dwStartTime);
413     var = dtStart;
414     m_GameScoreDB->AddParamter(TEXT("@StartTime"),adParamInput,adDate,sizeof(DATE),var);
415     COleDateTime dtEnd((time_t)pRecordGame->dwEndTime);
416     var = dtEnd;
417     m_GameScoreDB->AddParamter(TEXT("@EndTime"),adParamInput,adDate,sizeof(DATE),var);
418     var = pRecordGame->lScore;
419     m_GameScoreDB->AddParamter(TEXT("@Score"),adParamInput,adInteger,sizeof(long),var);
420     var = pRecordGame->szDetails;
421     m_GameScoreDB->AddParamter(TEXT("@Describe"),adParamInput,adVarChar,lstrlen(pRecordGame->szDetails),var);
422     var = pRecordGame->lRevenue;
423     m_GameScoreDB->AddParamter(TEXT("@Revenue"),adParamInput,adInteger,sizeof(long),var);
424 
425     return m_GameScoreDB->ExecuteCommand(false);
426 }
427 //解锁用户
428 bool CDataBaseSink::OnRequestUnLockUser(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize)
429 {
430     //效验参数
431     ASSERT(wDataSize==sizeof(DBR_GR_UnLockByUserID));
432     if (wDataSize!=sizeof(DBR_GR_UnLockByUserID)) return false;
433 
434     //执行查询
435     DBR_GR_UnLockByUserID * pUnLockByUserID=(DBR_GR_UnLockByUserID *)pDataBuffer;
436 
437     _variant_t var = pUnLockByUserID->dwUserID;
438     //执行存储过程
439     m_GameScoreDB->ClearAllParameters();
440     m_GameScoreDB->SetSPName("GSP_GP_ClearLockerByUID");
441     m_GameScoreDB->AddParamter(TEXT("@UID"),adParamInput,adInteger,sizeof(long),var);
442 
443     return m_GameScoreDB->ExecuteCommand(false);
444 }
445 
446 
447 //装载机器人
448 bool CDataBaseSink::OnRequestReadAIUser(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize)
449 {
450     try
451     {
452         LONG lReturnValue = 0;
453 
454         //变量定义
455         DBO_GR_AndroidUser AndroidUser;
456         ZeroMemory(&AndroidUser,sizeof(AndroidUser));
457 
458         //执行装载机器人
459         lReturnValue = SPLoadAndroidUser(m_pGameServiceOption->wKindID, m_pGameServiceOption->wServerID);
460 
461         //结果处理
462         if (lReturnValue!=0L )
463         {
464             //输出错误
465             m_pIEventService->ShowEventNotify("装载机器人失败",Level_Exception);
466             ASSERT(FALSE);
467         }
468         else
469         {
470             //读取数据
471             DWORD dwAndroidID=0L;
472             DWORD dwAndroidType=0L;
473             //读取信息
474             for (WORD i=0;i<CountArray(AndroidUser.dwAndroidID);i++)
475             {
476                 //结束判断
477                 if (m_GameScoreDB->IsEndRecordset()==true) break;
478 
479                 ////读取用户信息
480                 m_GameScoreDB->GetFieldValue(TEXT("UserID"),dwAndroidID);
481                 m_GameScoreDB->GetFieldValue(TEXT("Type"),dwAndroidType);
482 
483                 AndroidUser.dwAndroidID[AndroidUser.wAndroidCount]=dwAndroidID;
484                 AndroidUser.dwAndroidType[AndroidUser.wAndroidCount]=dwAndroidType;
485 
486                 AndroidUser.wAndroidCount++;
487 
488                 //移动记录
489                 m_GameScoreDB->MoveToNext();
490             }
491 
492             for (LONG index=0; index<CountArray(AndroidUser.dwAndroidID); index++)
493             {
494                 if(AndroidUser.dwAndroidID[index] == 0)
495                     break;
496 
497                 lReturnValue = 0;
498                 //执行装载机器人
499                 lReturnValue = SPLoadAndroidUserLogon(AndroidUser.dwAndroidID[index], m_pGameServiceOption->wKindID, m_pGameServiceOption->wServerID);
500                 //结果处理
501                 if (lReturnValue!=0L)
502                 {
503                     //输出错误
504                     m_pIEventService->ShowEventNotify("装载机器人详细信息失败",Level_Exception);
505                     ASSERT(FALSE);
506                 }
507                 else
508                 {
509                     //变量定义
510                     DBR_GR_LogonSuccess LogonSuccess;
511                     memset(&LogonSuccess,0,sizeof(LogonSuccess));
512 
513                     //读取用户信息
514                     m_GameScoreDB->GetFieldValue(TEXT("UserID"),LogonSuccess.dwUserID);
515                     m_GameScoreDB->GetFieldValue(TEXT("GameID"),LogonSuccess.dwGameID);
516                     m_GameScoreDB->GetFieldValue(TEXT("FaceID"),LogonSuccess.wFaceID);
517                     m_GameScoreDB->GetFieldValue(TEXT("GroupID"),LogonSuccess.dwGroupID);
518                     m_GameScoreDB->GetFieldValue(TEXT("UserRight"),LogonSuccess.dwUserRight);
519                     m_GameScoreDB->GetFieldValue(TEXT("MasterRight"),LogonSuccess.dwMasterRight);
520                     m_GameScoreDB->GetFieldValue(TEXT("Accounts"),LogonSuccess.szAccounts,sizeof(LogonSuccess.szAccounts));
521                     m_GameScoreDB->GetFieldValue(TEXT("Nickname"),LogonSuccess.szNickname,sizeof(LogonSuccess.szNickname));
522                     m_GameScoreDB->GetFieldValue(TEXT("GroupName"),LogonSuccess.szGroupName,sizeof(LogonSuccess.szGroupName));
523                     m_GameScoreDB->GetFieldValue(TEXT("UnderWrite"),LogonSuccess.szUnderWrite,sizeof(LogonSuccess.szUnderWrite));
524 
525                     //用户属性
526                     m_GameScoreDB->GetFieldValue(TEXT("Gender"),LogonSuccess.cbGender);
527                     m_GameScoreDB->GetFieldValue(TEXT("MemberOrder"),LogonSuccess.cbMemberOrder);
528                     m_GameScoreDB->GetFieldValue(TEXT("MasterOrder"),LogonSuccess.cbMasterOrder);
529                     m_GameScoreDB->GetFieldValue(TEXT("Vip"),LogonSuccess.bVip);
530 
531                     //读取游戏信息
532                     m_GameScoreDB->GetFieldValue(TEXT("Experience"),LogonSuccess.lExperience);
533                     m_GameScoreDB->GetFieldValue(TEXT("Score"),LogonSuccess.lScore);
534                     m_GameScoreDB->GetFieldValue(TEXT("Gold"),LogonSuccess.lGold);
535                     m_GameScoreDB->GetFieldValue(TEXT("PaiCoin"),LogonSuccess.lPaiCoin);
536                     m_GameScoreDB->GetFieldValue(TEXT("WinCount"),LogonSuccess.lWinCount);
537                     m_GameScoreDB->GetFieldValue(TEXT("LostCount"),LogonSuccess.lLostCount);
538                     m_GameScoreDB->GetFieldValue(TEXT("DrawCount"),LogonSuccess.lDrawCount);
539                     m_GameScoreDB->GetFieldValue(TEXT("FleeCount"),LogonSuccess.lFleeCount);
540 
541 
542                     //附加信息
543                     LogonSuccess.bAIFlage = TRUE;
544                     LogonSuccess.wAIType = AndroidUser.dwAndroidType[index];
545 
546                     //转化地址
547                     TCHAR szClientIP[16]=TEXT("");
548                     /*_snprintf(szClientIP,sizeof(szClientIP),TEXT("%d.%d.%d.%d"),rand()%255,rand()%255,rand()%255,rand()%255);*/
549                     _snprintf(szClientIP,sizeof(szClientIP),TEXT("%s"),tempIP[rand()%20]);
550                     CopyMemory(LogonSuccess.szLognoIP,szClientIP,sizeof(szClientIP));
551 
552                     //投递调度通知
553                     m_AttemperEvent.PostDataBaseEvent(DBR_GR_READ_ANDROID_SUCCESS,DataBaseEvent.wIndex,DataBaseEvent.wRoundID,
554                         &LogonSuccess,sizeof(LogonSuccess));
555                 }
556 
557             }
558 
559 
560             m_AttemperEvent.PostDataBaseEvent(DBR_GR_READ_ANDROID_FINISH,
561                 DataBaseEvent.wIndex,DataBaseEvent.wRoundID,
562                 NULL,0);
563         }
564 
565     }
566     catch (IADOError * pIADOError)
567     {
568         //输出错误
569         if (m_pIEventService!=NULL) m_pIEventService->ShowEventNotify(pIADOError->GetErrorDescribe(),Level_Exception);
570     }
571 
572     //关闭记录集
573     m_GameUserDB->CloseRecordset();
574     m_GameScoreDB->CloseRecordset();
575 
576     return true;
577 }
578 //I D 存储过程
579 LONG CDataBaseSink::SPLogonByUserID(DWORD dwUserID, LPCTSTR pszPassword, DWORD dwClientIP, LPCTSTR pszComputerID)
580 {
581     //效验参数
582     ASSERT(dwUserID!=0L);
583     ASSERT(pszPassword!=NULL);
584 
585     //转化地址
586     TCHAR szClientIP[16]=TEXT("");
587     BYTE * pClientIP=(BYTE *)&dwClientIP;
588     _snprintf(szClientIP,sizeof(szClientIP),TEXT("%d.%d.%d.%d"),pClientIP[0],pClientIP[1],pClientIP[2],pClientIP[3]);
589 
590     _variant_t var = 0;
591     //执行存储过程
592     m_GameScoreDB->ClearAllParameters();
593     m_GameScoreDB->SetSPName("GSP_GR_EfficacyUserID");
594     m_GameScoreDB->AddParamter(TEXT("RETURN_VALUE"),adParamReturnValue,adInteger,sizeof(long),var);
595     var = dwUserID;
596     m_GameScoreDB->AddParamter(TEXT("@dwUserID"),adParamInput,adInteger,sizeof(long),var);
597     var = pszPassword;
598     m_GameScoreDB->AddParamter(TEXT("@strPassword"),adParamInput,adChar,PASS_LEN,var);
599     var = szClientIP;
600     m_GameScoreDB->AddParamter(TEXT("@strClientIP"),adParamInput,adVarChar,lstrlen(szClientIP),var);
601     var = pszComputerID;
602     m_GameScoreDB->AddParamter(TEXT("@strMachineSerial"),adParamInput,adVarChar,CountString(pszComputerID),var);
603     var = m_pGameServiceAttrib->wKindID;
604     m_GameScoreDB->AddParamter(TEXT("@wKindID"),adParamInput,adInteger,sizeof(long),var);
605     var = m_pGameServiceOption->wServerID;
606     m_GameScoreDB->AddParamter(TEXT("@wServerID"),adParamInput,adInteger,sizeof(long),var);
607 
608   /*  TCHAR strServerId[10]=TEXT("");
609     _snprintf(strServerId,sizeof(strServerId),TEXT("Score"));
610     var = strServerId;
611     m_GameScoreDB->AddParamter(TEXT("@MoneyID"),adParamInput,adVarChar,lstrlen(strServerId),var);*/
612 
613     m_GameScoreDB->ExecuteCommand(true);
614 
615     return m_GameScoreDB->GetReturnValue();
616 }
617 
618 //写分存储过程
619 LONG CDataBaseSink::SPWriteUserScore(DWORD dwUserID, DWORD dwPlayTimeCount, DWORD dwOnLineTimeCount, DWORD dwClientIP, LONG lRevenue, tagUserScore & UserScore)
620 {
621     //效验参数
622     ASSERT(dwUserID!=0L);
623 
624     //转化地址
625     TCHAR szClientIP[16]=TEXT("");
626     BYTE * pClientIP=(BYTE *)&dwClientIP;
627     _snprintf(szClientIP,sizeof(szClientIP),TEXT("%d.%d.%d.%d"),pClientIP[0],pClientIP[1],pClientIP[2],pClientIP[3]);
628 
629     _variant_t var = 0;
630     //执行存储过程
631     m_GameScoreDB->ClearAllParameters();
632     m_GameScoreDB->SetSPName("GSP_GR_WriteGameScore");
633     m_GameScoreDB->AddParamter(TEXT("RETURN_VALUE"),adParamReturnValue,adInteger,sizeof(long),var);
634     var = dwUserID;
635     m_GameScoreDB->AddParamter(TEXT("@dwUserID"),adParamInput,adInteger,sizeof(long),var);
636     var = UserScore.lScore;
637     m_GameScoreDB->AddParamter(TEXT("@lScore"),adParamInput,adInteger,sizeof(long),var);
638     var = UserScore.lGold;
639     m_GameScoreDB->AddParamter(TEXT("@lGold"),adParamInput,adInteger,sizeof(long),var);
640     var = UserScore.lExperience;
641     m_GameScoreDB->AddParamter(TEXT("@lExperience"),adParamInput,adInteger,sizeof(long),var);
642     var = lRevenue;
643     m_GameScoreDB->AddParamter(TEXT("@lRevenue"),adParamInput,adInteger,sizeof(long),var);
644     var = UserScore.lWinCount;
645     m_GameScoreDB->AddParamter(TEXT("@lWinCount"),adParamInput,adInteger,sizeof(long),var);
646     var = UserScore.lLostCount;
647     m_GameScoreDB->AddParamter(TEXT("@lLostCount"),adParamInput,adInteger,sizeof(long),var);
648     var = UserScore.lDrawCount;
649     m_GameScoreDB->AddParamter(TEXT("@lDrawCount"),adParamInput,adInteger,sizeof(long),var);
650     var = UserScore.lFleeCount;
651     m_GameScoreDB->AddParamter(TEXT("@lFleeCount"),adParamInput,adInteger,sizeof(long),var);
652     var = dwPlayTimeCount;
653     m_GameScoreDB->AddParamter(TEXT("@dwPlayTimeCount"),adParamInput,adInteger,sizeof(long),var);
654     var = dwOnLineTimeCount;
655     m_GameScoreDB->AddParamter(TEXT("@dwOnLineTimeCount"),adParamInput,adInteger,sizeof(long),var);
656     var = m_pGameServiceAttrib->wKindID;
657     m_GameScoreDB->AddParamter(TEXT("@wKindID"),adParamInput,adInteger,sizeof(long),var);
658     var = m_pGameServiceOption->wServerID;
659     m_GameScoreDB->AddParamter(TEXT("@wServerID"),adParamInput,adInteger,sizeof(long),var);
660     var = szClientIP;
661     m_GameScoreDB->AddParamter(TEXT("@strClientIP"),adParamInput,adVarChar,lstrlen(szClientIP),var);
662     m_GameScoreDB->ExecuteCommand(false);
663 
664     return m_GameScoreDB->GetReturnValue();
665 }
666 
667 //离开存储过程
668 LONG CDataBaseSink::SPLeaveGameServer(DWORD dwUserID, DWORD dwPlayTimeCount, DWORD dwOnLineTimeCount, DWORD dwClientIP, LONG lRevenue, tagUserScore & UserScore)
669 {
670     //效验参数
671     ASSERT(dwUserID!=0L);
672 
673     //转化地址
674     TCHAR szClientIP[16]=TEXT("");
675     BYTE * pClientIP=(BYTE *)&dwClientIP;
676     _snprintf(szClientIP,sizeof(szClientIP),TEXT("%d.%d.%d.%d"),pClientIP[0],pClientIP[1],pClientIP[2],pClientIP[3]);
677 
678     _variant_t var = 0;
679     //执行存储过程
680     m_GameScoreDB->ClearAllParameters();
681     m_GameScoreDB->SetSPName("GSP_GR_LeaveGameServer");
682     m_GameScoreDB->AddParamter(TEXT("RETURN_VALUE"),adParamReturnValue,adInteger,sizeof(long),var);
683     var = dwUserID;
684     m_GameScoreDB->AddParamter(TEXT("@dwUserID"),adParamInput,adInteger,sizeof(long),var);
685     var = UserScore.lScore;
686     m_GameScoreDB->AddParamter(TEXT("@lScore"),adParamInput,adInteger,sizeof(long),var);
687     var = UserScore.lGold;
688     m_GameScoreDB->AddParamter(TEXT("@lGold"),adParamInput,adInteger,sizeof(long),var);
689     var = lRevenue;
690     m_GameScoreDB->AddParamter(TEXT("@lRevenue"),adParamInput,adInteger,sizeof(long),var);
691     var = UserScore.lWinCount;
692     m_GameScoreDB->AddParamter(TEXT("@lWinCount"),adParamInput,adInteger,sizeof(long),var);
693     var = UserScore.lLostCount;
694     m_GameScoreDB->AddParamter(TEXT("@lLostCount"),adParamInput,adInteger,sizeof(long),var);
695     var = UserScore.lDrawCount;
696     m_GameScoreDB->AddParamter(TEXT("@lDrawCount"),adParamInput,adInteger,sizeof(long),var);
697     var = UserScore.lFleeCount;
698     m_GameScoreDB->AddParamter(TEXT("@lFleeCount"),adParamInput,adInteger,sizeof(long),var);
699     var = UserScore.lExperience;
700     m_GameScoreDB->AddParamter(TEXT("@lExperience"),adParamInput,adInteger,sizeof(long),var);
701     var = dwPlayTimeCount;
702     m_GameScoreDB->AddParamter(TEXT("@dwPlayTimeCount"),adParamInput,adInteger,sizeof(long),var);
703     var = dwOnLineTimeCount;
704     m_GameScoreDB->AddParamter(TEXT("@dwOnLineTimeCount"),adParamInput,adInteger,sizeof(long),var);
705     var = m_pGameServiceAttrib->wKindID;
706     m_GameScoreDB->AddParamter(TEXT("@wKindID"),adParamInput,adInteger,sizeof(long),var);
707     var = m_pGameServiceOption->wServerID;
708     m_GameScoreDB->AddParamter(TEXT("@wServerID"),adParamInput,adInteger,sizeof(long),var);
709     var = szClientIP;
710     m_GameScoreDB->AddParamter(TEXT("@strClientIP"),adParamInput,adVarChar,lstrlen(szClientIP),var);
711 
712     /*TCHAR strServerId[10]=TEXT("");
713     _snprintf(strServerId,sizeof(strServerId),TEXT("Score"));
714     var = strServerId;
715     m_GameScoreDB->AddParamter(TEXT("@MoneyID"),adParamInput,adVarChar,lstrlen(strServerId),var);*/
716 
717     m_GameScoreDB->ExecuteCommand(false);
718     return m_GameScoreDB->GetReturnValue();
719 }
720 
721 //禁号存储过程
722 LONG CDataBaseSink::SPCongealAccounts(DWORD dwUserID)
723 {
724     ////效验参数
725     //ASSERT(dwUserID!=0L);
726 
727     ////执行存储过程
728     //m_GameUserDB->ClearAllParameters();
729     //m_GameUserDB->SetSPName("GSP_GR_CongealAccounts");
730     //m_GameUserDB->AddParamter(TEXT("RETURN_VALUE"),adParamReturnValue,adInteger,sizeof(long),_variant_t((long)0));
731     //m_GameUserDB->AddParamter(TEXT("@dwUserID"),adParamInput,adInteger,sizeof(long),_variant_t((long)dwUserID));
732     //m_GameUserDB->ExecuteCommand(false);
733 
734     //return m_GameUserDB->GetReturnValue();
735 
736     return 0;
737 }
738 
739 //权限存储过程
740 LONG CDataBaseSink::SPSetUserGameRight(DWORD dwUserID, DWORD dwUserRight, DWORD dwMasterUserID, DWORD dwClientIP)
741 {
742     //效验参数
743     /*ASSERT(dwUserID!=0L);
744 
745     //转化地址
746     TCHAR szClientIP[16]=TEXT("");
747     BYTE * pClientIP=(BYTE *)&dwClientIP;
748     _snprintf(szClientIP,sizeof(szClientIP),TEXT("%d.%d.%d.%d"),pClientIP[0],pClientIP[1],pClientIP[2],pClientIP[3]);
749 
750     //执行存储过程
751     m_GameScoreDB->ClearAllParameters();
752     m_GameScoreDB->SetSPName("GSP_GR_SetUserRight");
753     m_GameScoreDB->AddParamter(TEXT("RETURN_VALUE"),adParamReturnValue,adInteger,sizeof(long),_variant_t((long)0));
754     m_GameScoreDB->AddParamter(TEXT("@dwUserID"),adParamInput,adInteger,sizeof(long),_variant_t((long)dwUserID));
755     m_GameScoreDB->AddParamter(TEXT("@dwUserRight"),adParamInput,adInteger,sizeof(long),_variant_t((long)dwUserRight));
756     m_GameScoreDB->AddParamter(TEXT("@dwMasterUserID"),adParamInput,adInteger,sizeof(long),_variant_t((long)dwMasterUserID));
757     m_GameScoreDB->AddParamter(TEXT("@strClientIP"),adParamInput,adVarChar,lstrlen(szClientIP),_variant_t(szClientIP));
758     m_GameScoreDB->ExecuteCommand(false);
759 
760     return m_GameScoreDB->GetReturnValue();*/
761     return 0;
762 }
763 
764 //权限存储过程
765 LONG CDataBaseSink::SPSetUserAccountsRight(DWORD dwUserID, DWORD dwUserRight, DWORD dwMasterUserID, DWORD dwClientIP)
766 {
767     //效验参数
768     /*ASSERT(dwUserID!=0L);
769 
770     //转化地址
771     TCHAR szClientIP[16]=TEXT("");
772     BYTE * pClientIP=(BYTE *)&dwClientIP;
773     _snprintf(szClientIP,sizeof(szClientIP),TEXT("%d.%d.%d.%d"),pClientIP[0],pClientIP[1],pClientIP[2],pClientIP[3]);
774 
775     //执行存储过程
776     m_GameUserDB->ClearAllParameters();
777     m_GameUserDB->SetSPName("GSP_GR_SetUserRight");
778     m_GameUserDB->AddParamter(TEXT("RETURN_VALUE"),adParamReturnValue,adInteger,sizeof(long),_variant_t((long)0));
779     m_GameUserDB->AddParamter(TEXT("@dwUserID"),adParamInput,adInteger,sizeof(long),_variant_t((long)dwUserID));
780     m_GameUserDB->AddParamter(TEXT("@dwUserRight"),adParamInput,adInteger,sizeof(long),_variant_t((long)dwUserRight));
781     m_GameUserDB->AddParamter(TEXT("@dwMasterUserID"),adParamInput,adInteger,sizeof(long),_variant_t((long)dwMasterUserID));
782     m_GameUserDB->AddParamter(TEXT("@strClientIP"),adParamInput,adVarChar,lstrlen(szClientIP),_variant_t(szClientIP));
783     m_GameUserDB->ExecuteCommand(false);
784 
785     return m_GameUserDB->GetReturnValue();*/
786     return 0;
787 }
788 
789 //读取机器人ID帐号
790 LONG CDataBaseSink::SPLoadAndroidUser(WORD wKindID, WORD wServerID)
791 {
792     _variant_t var = 0;
793     //执行存储过程
794     m_GameScoreDB->ClearAllParameters();
795     m_GameScoreDB->SetSPName("GSP_GR_LoadAndroidUser");
796     m_GameScoreDB->AddParamter(TEXT("RETURN_VALUE"),adParamReturnValue,adBigInt,sizeof(long),var);
797     var = wKindID;
798     m_GameScoreDB->AddParamter(TEXT("@wKindID"),adParamInput,adSmallInt,sizeof(WORD),var);
799     var = wServerID;
800     m_GameScoreDB->AddParamter(TEXT("@wServerID"),adParamInput,adSmallInt,sizeof(WORD),var);
801 
802     m_GameScoreDB->ExecuteCommand(true);
803 
804     return m_GameScoreDB->GetReturnValue();
805 }
806 
807 //读取机器人详细信息
808 LONG CDataBaseSink::SPLoadAndroidUserLogon(DWORD dwUserID, WORD wKindID, WORD wServerID)
809 {
810     _variant_t var = 0;
811     //执行存储过程
812     m_GameScoreDB->ClearAllParameters();
813     //m_GameScoreDB->SetSPName("GSP_GR_EfficacyUserID");
814     m_GameScoreDB->SetSPName("GSP_GR_EfficacyAIID");
815     m_GameScoreDB->AddParamter(TEXT("RETURN_VALUE"),adParamReturnValue,adBigInt,4,var);
816     var = dwUserID;
817     m_GameScoreDB->AddParamter(TEXT("@dwUserID"),adParamInput,adBigInt,sizeof(DWORD),var);
818     var = wKindID;
819     m_GameScoreDB->AddParamter(TEXT("@wKindID"),adParamInput,adSmallInt,sizeof(WORD),var);
820     var = wServerID;
821     m_GameScoreDB->AddParamter(TEXT("@wServerID"),adParamInput,adSmallInt,sizeof(WORD),var);
822 
823     m_GameScoreDB->ExecuteCommand(true);
824 
825     return m_GameScoreDB->GetReturnValue();
826 }
827 
828 //重置机器人修改触发字段
829 LONG CDataBaseSink::SPResetChanged(WORD wKindID, WORD wServerID)
830 {
831     //执行存储过程
832     _variant_t var = 0;
833     m_GameScoreDB->ClearAllParameters();
834     m_GameScoreDB->SetSPName("GSP_316_ResetChanged");
835     m_GameScoreDB->AddParamter(TEXT("RETURN_VALUE"),adParamReturnValue,adInteger,sizeof(long),var);
836     var = wKindID;
837     m_GameScoreDB->AddParamter(TEXT("@KindID"),adParamInput,adInteger,sizeof(WORD),var);
838     var = wServerID;
839     m_GameScoreDB->AddParamter(TEXT("@ServerID"),adParamInput,adInteger,sizeof(WORD),var);
840 
841     return m_GameScoreDB->ExecuteCommand(false);
842 }
843 
844 //重置程序异常触发修改触发字段
845 LONG CDataBaseSink::SPResetAbnormity(WORD wKindID, WORD wServerID)
846 {
847     //执行存储过程
848     _variant_t var = 0;
849     m_GameScoreDB->ClearAllParameters();
850     m_GameScoreDB->SetSPName("GSP_316_ResetAbnormity");
851     m_GameScoreDB->AddParamter(TEXT("RETURN_VALUE"),adParamReturnValue,adInteger,sizeof(long),var);
852     var = wKindID;
853     m_GameScoreDB->AddParamter(TEXT("@KindID"),adParamInput,adInteger,sizeof(WORD),var);
854     var = wServerID;
855     m_GameScoreDB->AddParamter(TEXT("@ServerID"),adParamInput,adInteger,sizeof(WORD),var);
856 
857     return m_GameScoreDB->ExecuteCommand(false);
858 }
859 //////////////////////////////////////////////////////////////////////////
DataBaseSink.cpp

头文件Afxinet.h :

bubuko.com,布布扣
  1 // This is a part of the Microsoft Foundation Classes C++ library.
  2 // Copyright (C) Microsoft Corporation
  3 // All rights reserved.
  4 //
  5 // This source code is only intended as a supplement to the
  6 // Microsoft Foundation Classes Reference and related
  7 // electronic documentation provided with the library.
  8 // See these sources for detailed information regarding the
  9 // Microsoft Foundation Classes product.
 10 
 11 #ifndef __AFXINET_H_
 12 #define __AFXINET_H_
 13 
 14 #pragma once
 15 
 16 #ifndef __AFX_H__
 17     #include <afx.h>
 18 #endif
 19 
 20 #ifndef _WININET_
 21 #include <wininet.h>
 22 #endif
 23 
 24 #ifdef _AFXDLL
 25 #pragma comment(lib, "wininet.lib")
 26 #endif
 27 
 28 #ifdef _AFX_MINREBUILD
 29 #pragma component(minrebuild, off)
 30 #endif
 31 
 32 /////////////////////////////////////////////////////////////////////////////
 33 // classes that are declared in this file
 34 
 35 class CInternetSession; // from CObject
 36 
 37 class CGopherLocator;   // from CObject
 38 
 39 class CInternetFile;    // from CStdioFile (FILETXT.CPP)
 40     class CHttpFile;
 41     class CGopherFile;
 42 
 43 class CInternetConnection;
 44     class CFtpConnection;
 45     class CGopherConnection;
 46     class CHttpConnection;
 47 
 48 class CFtpFileFind;     // from CFileFind (FILEFIND.CPP)
 49 class CGopherFileFind;
 50 
 51 class CInternetException;
 52 
 53 /////////////////////////////////////////////////////////////////////////////
 54 
 55 #undef AFX_DATA
 56 #define AFX_DATA AFX_CORE_DATA
 57 
 58 /////////////////////////////////////////////////////////////////////////////
 59 // Global Functions
 60 
 61 BOOL AFXAPI AfxParseURL(LPCTSTR pstrURL, DWORD& dwServiceType,
 62     CString& strServer, CString& strObject, INTERNET_PORT& nPort);
 63 BOOL AFXAPI AfxParseURLEx(LPCTSTR pstrURL, DWORD& dwServiceType,
 64     CString& strServer, CString& strObject, INTERNET_PORT& nPort,
 65     CString& strUsername, CString& strPassword, DWORD dwFlags = 0);
 66 
 67 DWORD AFXAPI AfxGetInternetHandleType(HINTERNET hQuery);
 68 
 69 // see CInternetException at the bottom of this file
 70 
 71 void AFXAPI AfxThrowInternetException(DWORD_PTR dwContext, DWORD dwError = 0);
 72 
 73 // these are defined by WININET.H
 74 
 75 #define AFX_INET_SERVICE_FTP        INTERNET_SERVICE_FTP
 76 #define AFX_INET_SERVICE_HTTP       INTERNET_SERVICE_HTTP
 77 #define AFX_INET_SERVICE_GOPHER     INTERNET_SERVICE_GOPHER
 78 
 79 // these are types that MFC parsing functions understand
 80 
 81 #define AFX_INET_SERVICE_UNK        0x1000
 82 #define AFX_INET_SERVICE_FILE       (AFX_INET_SERVICE_UNK+1)
 83 #define AFX_INET_SERVICE_MAILTO     (AFX_INET_SERVICE_UNK+2)
 84 #define AFX_INET_SERVICE_MID        (AFX_INET_SERVICE_UNK+3)
 85 #define AFX_INET_SERVICE_CID        (AFX_INET_SERVICE_UNK+4)
 86 #define AFX_INET_SERVICE_NEWS       (AFX_INET_SERVICE_UNK+5)
 87 #define AFX_INET_SERVICE_NNTP       (AFX_INET_SERVICE_UNK+6)
 88 #define AFX_INET_SERVICE_PROSPERO   (AFX_INET_SERVICE_UNK+7)
 89 #define AFX_INET_SERVICE_TELNET     (AFX_INET_SERVICE_UNK+8)
 90 #define AFX_INET_SERVICE_WAIS       (AFX_INET_SERVICE_UNK+9)
 91 #define AFX_INET_SERVICE_AFS        (AFX_INET_SERVICE_UNK+10)
 92 #define AFX_INET_SERVICE_HTTPS      (AFX_INET_SERVICE_UNK+11)
 93 
 94 /////////////////////////////////////////////////////////////////////////////
 95 // classes that are declared in this file
 96 
 97 class CInternetSession : public CObject
 98 {
 99 public:
100     /* explicit */ CInternetSession(LPCTSTR pstrAgent = NULL,
101         DWORD_PTR dwContext = 1,
102         DWORD dwAccessType = PRE_CONFIG_INTERNET_ACCESS,
103         LPCTSTR pstrProxyName = NULL,
104         LPCTSTR pstrProxyBypass = NULL,
105         DWORD dwFlags = 0);
106 
107     BOOL QueryOption(DWORD dwOption, LPVOID lpBuffer, LPDWORD lpdwBufLen) const;
108     BOOL QueryOption(DWORD dwOption, DWORD& dwValue) const;
109 
110     BOOL SetOption(DWORD dwOption, LPVOID lpBuffer, DWORD dwBufferLength,
111             DWORD dwFlags = 0);
112     BOOL SetOption(DWORD dwOption, DWORD dwValue, DWORD dwFlags = 0);
113 
114     CStdioFile* OpenURL(LPCTSTR pstrURL,
115         DWORD_PTR dwContext = 1, DWORD dwFlags = INTERNET_FLAG_TRANSFER_ASCII,
116         LPCTSTR pstrHeaders = NULL, DWORD dwHeadersLength = 0);
117 
118     CFtpConnection* GetFtpConnection(LPCTSTR pstrServer,
119         LPCTSTR pstrUserName = NULL, LPCTSTR pstrPassword = NULL,
120         INTERNET_PORT nPort = INTERNET_INVALID_PORT_NUMBER,
121         BOOL bPassive = FALSE);
122 
123     CHttpConnection* GetHttpConnection(LPCTSTR pstrServer,
124         INTERNET_PORT nPort = INTERNET_INVALID_PORT_NUMBER,
125         LPCTSTR pstrUserName = NULL, LPCTSTR pstrPassword = NULL);
126     CHttpConnection* GetHttpConnection(LPCTSTR pstrServer, DWORD dwFlags,
127         INTERNET_PORT nPort = INTERNET_INVALID_PORT_NUMBER,
128         LPCTSTR pstrUserName = NULL, LPCTSTR pstrPassword = NULL);
129 
130     CGopherConnection* GetGopherConnection(LPCTSTR pstrServer,
131         LPCTSTR pstrUserName = NULL, LPCTSTR pstrPassword = NULL,
132         INTERNET_PORT nPort = INTERNET_INVALID_PORT_NUMBER);
133 
134     BOOL EnableStatusCallback(BOOL bEnable = TRUE);
135 
136 // Operations
137 
138     DWORD_PTR GetContext() const;
139     operator HINTERNET() const;
140     virtual void Close();
141 
142     // cookies
143     static BOOL SetCookie(LPCTSTR pstrUrl, LPCTSTR pstrCookieName, LPCTSTR pstrCookieData);
144     static BOOL GetCookie(_In_z_ LPCTSTR pstrUrl, _In_z_ LPCTSTR pstrCookieName, _Out_z_cap_(dwBufLen) LPTSTR pstrCookieData, _In_ DWORD dwBufLen);
145     static DWORD GetCookieLength(LPCTSTR pstrUrl, LPCTSTR pstrCookieName);
146     static BOOL GetCookie(LPCTSTR pstrUrl, LPCTSTR pstrCookieName, CString& strCookieData);
147 
148 // Overridables
149     virtual void OnStatusCallback(DWORD_PTR dwContext, DWORD dwInternetStatus,
150         LPVOID lpvStatusInformation, DWORD dwStatusInformationLength);
151 
152 // Implementation
153     DECLARE_DYNAMIC(CInternetSession)
154     ~CInternetSession();
155 
156 protected:
157     DWORD_PTR m_dwContext;
158     HINTERNET m_hSession;
159     INTERNET_STATUS_CALLBACK m_pOldCallback;
160     BOOL m_bCallbackEnabled;
161 
162 public:
163 #ifdef _DEBUG
164     virtual void Dump(CDumpContext& dc) const;
165 #endif
166 };
167 
168 
169 ////////////////////////////////////////////////////////////////////////////
170 // Internet File Access Wrapper
171 
172 class CInternetFile : public CStdioFile
173 {
174 // Constructors
175 protected:
176     CInternetFile(HINTERNET hFile, LPCTSTR pstrFileName,
177         CInternetConnection* pConnection, BOOL bReadMode);
178     CInternetFile(HINTERNET hFile, HINTERNET hSession,
179         LPCTSTR pstrFileName, LPCTSTR pstrServer, DWORD_PTR dwContext,
180         BOOL bReadMode);
181 
182 // Attributes
183 protected:
184     HINTERNET m_hFile;
185 public:
186     operator HINTERNET() const;
187     DWORD_PTR GetContext() const;
188 
189 // Operations
190     BOOL SetWriteBufferSize(UINT nWriteSize);
191     BOOL SetReadBufferSize(UINT nReadSize);
192 
193     BOOL QueryOption(DWORD dwOption, LPVOID lpBuffer, LPDWORD lpdwBufLen) const;
194     BOOL QueryOption(DWORD dwOption, DWORD& dwValue) const;
195 
196     BOOL SetOption(DWORD dwOption, LPVOID lpBuffer, DWORD dwBufferLength,
197             DWORD dwFlags = 0);
198     BOOL SetOption(DWORD dwOption, DWORD dwValue, DWORD dwFlags = 0);
199 
200 // Overridables
201     virtual ULONGLONG Seek(LONGLONG lOffset, UINT nFrom);
202 
203     virtual UINT Read(void* lpBuf, UINT nCount);
204     virtual void Write(const void* lpBuf, UINT nCount);
205 
206     virtual void Abort();
207     virtual void Flush();
208 
209     virtual void Close();
210     virtual ULONGLONG GetLength() const;
211 
212     virtual BOOL ReadString(CString& rString);
213     virtual LPTSTR ReadString(_Out_z_cap_(nMax) LPTSTR pstr, _In_ UINT nMax);
214     virtual void WriteString(LPCTSTR pstr);
215 
216     // Not supported by CInternetFile
217     void LockRange(ULONGLONG dwPos, ULONGLONG dwCount);
218     void UnlockRange(ULONGLONG dwPos, ULONGLONG dwCount);
219     CFile* Duplicate() const;
220     virtual void SetLength(ULONGLONG dwNewLen);
221 
222 // Implementation
223 public:
224     virtual ~CInternetFile();
225 
226 protected:
227     BOOL m_bReadMode;
228     DWORD_PTR m_dwContext;
229     HINTERNET m_hConnection;
230 
231     CString m_strServerName;
232 
233     UINT m_nWriteBufferSize;
234     UINT m_nWriteBufferPos;
235     LPBYTE m_pbWriteBuffer;
236 
237     UINT m_nReadBufferSize;
238     UINT m_nReadBufferPos;
239     LPBYTE m_pbReadBuffer;
240     UINT m_nReadBufferBytes;
241 
242 #ifdef _DEBUG
243     virtual void AssertValid() const;
244     virtual void Dump(CDumpContext& dc) const;
245 #endif
246 
247     friend class CInternetSession;
248     friend class CFtpConnection;
249     friend class CHttpConnection;
250     friend class CGopherConnection;
251     DECLARE_DYNAMIC(CInternetFile)
252 };
253 
254 
255 class CHttpFile : public CInternetFile
256 {
257 // Constructors
258 protected:
259     CHttpFile(HINTERNET hFile, HINTERNET hSession, LPCTSTR pstrObject,
260         LPCTSTR pstrServer, LPCTSTR pstrVerb, DWORD_PTR dwContext);
261     CHttpFile(HINTERNET hFile, LPCTSTR pstrVerb, LPCTSTR pstrObject,
262         CHttpConnection* pConnection);
263 
264 // Operations
265 public:
266     BOOL AddRequestHeaders(LPCTSTR pstrHeaders,
267         DWORD dwFlags = HTTP_ADDREQ_FLAG_ADD_IF_NEW, int dwHeadersLen = -1);
268     BOOL AddRequestHeaders(CString& str,
269         DWORD dwFlags = HTTP_ADDREQ_FLAG_ADD_IF_NEW);
270 
271     BOOL SendRequest(LPCTSTR pstrHeaders = NULL, DWORD dwHeadersLen = 0,
272         LPVOID lpOptional = NULL, DWORD dwOptionalLen = 0);
273     BOOL SendRequest(CString& strHeaders,
274         LPVOID lpOptional = NULL, DWORD dwOptionalLen = 0);
275     BOOL SendRequestEx(DWORD dwTotalLen,
276         DWORD dwFlags = HSR_INITIATE,    DWORD_PTR dwContext = 1);
277     BOOL SendRequestEx(LPINTERNET_BUFFERS lpBuffIn,
278         LPINTERNET_BUFFERS lpBuffOut, DWORD dwFlags = HSR_INITIATE,
279         DWORD_PTR dwContext = 1);
280     BOOL EndRequest(DWORD dwFlags = 0,
281         LPINTERNET_BUFFERS lpBuffIn = NULL, DWORD_PTR dwContext = 1);
282     BOOL QueryInfo(DWORD dwInfoLevel, LPVOID lpvBuffer,
283         LPDWORD lpdwBufferLength, LPDWORD lpdwIndex = NULL) const;
284     BOOL QueryInfo(DWORD dwInfoLevel, CString& str,
285         LPDWORD dwIndex = NULL) const;
286     BOOL QueryInfo(DWORD dwInfoLevel, SYSTEMTIME* pSysTime,
287         LPDWORD dwIndex = NULL) const;
288     BOOL QueryInfo(DWORD dwInfoLevel, DWORD& dwResult,
289         LPDWORD dwIndex = NULL) const;
290     BOOL QueryInfoStatusCode(DWORD& dwStatusCode) const;
291 
292     DWORD ErrorDlg(CWnd* pParent = NULL,
293         DWORD dwError = ERROR_INTERNET_INCORRECT_PASSWORD,
294         DWORD dwFlags = FLAGS_ERROR_UI_FLAGS_GENERATE_DATA | FLAGS_ERROR_UI_FLAGS_CHANGE_OPTIONS,
295         LPVOID* lppvData = NULL);
296 
297 // Attributes
298 public:
299     CString GetVerb() const;
300 
301 #pragma push_macro("GetObject")
302 #undef GetObject
303     CString _AFX_FUNCNAME(GetObject)() const;
304     CString GetObject() const;
305 #pragma pop_macro("GetObject")
306 
307     virtual CString GetFileURL() const;
308 
309 // Implementation
310 public:
311     virtual ~CHttpFile();
312 protected:
313     CString m_strObject;
314     CString m_strVerb;
315 
316 #ifdef _DEBUG
317     virtual void AssertValid() const;
318     virtual void Dump(CDumpContext& dc) const;
319 #endif
320 
321     friend class CHttpConnection;
322     friend class CInternetSession;
323     DECLARE_DYNAMIC(CHttpFile)
324 };
325 
326 // class CGopherFile is declared after CGopherLocator, below
327 
328 
329 ////////////////////////////////////////////////////////////////////////////
330 // Connection types
331 
332 class CInternetConnection : public CObject
333 {
334 public:
335     CInternetConnection(CInternetSession* pSession, LPCTSTR pstrServer,
336         INTERNET_PORT nPort = INTERNET_INVALID_PORT_NUMBER,
337         DWORD_PTR dwContext = 1);
338 
339 // Operations
340     operator HINTERNET() const;
341     DWORD_PTR GetContext() const;
342     CInternetSession* GetSession() const;
343 
344     CString GetServerName() const;
345 
346     BOOL QueryOption(DWORD dwOption, LPVOID lpBuffer, LPDWORD lpdwBufLen) const;
347     BOOL QueryOption(DWORD dwOption, DWORD& dwValue) const;
348 
349     BOOL SetOption(DWORD dwOption, LPVOID lpBuffer, DWORD dwBufferLength,
350             DWORD dwFlags = 0);
351     BOOL SetOption(DWORD dwOption, DWORD dwValue, DWORD dwFlags = 0);
352 
353     virtual void Close();
354 
355 // Implementation
356 protected:
357     HINTERNET m_hConnection;
358     DWORD_PTR m_dwContext;
359     CInternetSession* m_pSession;
360 
361     CString m_strServerName;
362     INTERNET_PORT m_nPort;
363 
364 public:
365     ~CInternetConnection();
366     DECLARE_DYNAMIC(CInternetConnection)
367 
368 #ifdef _DEBUG
369     virtual void Dump(CDumpContext& dc) const;
370     void AssertValid() const;
371 #endif
372 };
373 
374 class CFtpConnection : public CInternetConnection
375 {
376 public:
377     enum CmdResponseType
378     {
379         CmdRespNone = 0,
380         CmdRespRead,
381         CmdRespWrite
382     };
383 
384 public:
385     CFtpConnection(CInternetSession* pSession, HINTERNET hConnected,
386         LPCTSTR pstrServer, DWORD_PTR dwContext);
387     CFtpConnection(CInternetSession* pSession, LPCTSTR pstrServer,
388         LPCTSTR pstrUserName = NULL, LPCTSTR pstrPassword = NULL,
389         DWORD_PTR dwContext = 0,
390         INTERNET_PORT nPort = INTERNET_INVALID_PORT_NUMBER,
391         BOOL bPassive = FALSE);
392 
393 #pragma push_macro("SetCurrentDirectory")
394 #undef SetCurrentDirectory
395     BOOL _AFX_FUNCNAME(SetCurrentDirectory)(LPCTSTR pstrDirName);
396     BOOL SetCurrentDirectory(LPCTSTR pstrDirName);
397 #pragma pop_macro("SetCurrentDirectory")
398 
399     BOOL GetCurrentDirectory(CString& strDirName) const;
400     BOOL GetCurrentDirectory(_Out_z_cap_post_count_(*lpdwLen, *lpdwLen) LPTSTR pstrDirName, _Inout_ LPDWORD lpdwLen) const;
401     BOOL GetCurrentDirectoryAsURL(_Out_z_cap_post_count_(*lpdwLen, *lpdwLen) LPTSTR pstrName, _Inout_ LPDWORD lpdwLen) const;
402     BOOL GetCurrentDirectoryAsURL(CString& strDirName) const;
403 
404     BOOL RemoveDirectory(LPCTSTR pstrDirName);
405 #pragma push_macro("CreateDirectory")
406 #undef CreateDirectory
407     BOOL _AFX_FUNCNAME(CreateDirectory)(LPCTSTR pstrDirName);
408     BOOL CreateDirectory(LPCTSTR pstrDirName);
409 #pragma pop_macro("CreateDirectory")
410     BOOL Rename(LPCTSTR pstrExisting, LPCTSTR pstrNew);
411     BOOL Remove(LPCTSTR pstrFileName);
412 
413     BOOL PutFile(LPCTSTR pstrLocalFile, LPCTSTR pstrRemoteFile,
414         DWORD dwFlags = FTP_TRANSFER_TYPE_BINARY, DWORD_PTR dwContext = 1);
415 
416     BOOL GetFile(LPCTSTR pstrRemoteFile, LPCTSTR pstrLocalFile,
417         BOOL bFailIfExists = TRUE,
418         DWORD dwAttributes = FILE_ATTRIBUTE_NORMAL,
419         DWORD dwFlags = FTP_TRANSFER_TYPE_BINARY, DWORD_PTR dwContext = 1);
420 
421     CInternetFile* OpenFile(LPCTSTR pstrFileName,
422         DWORD dwAccess = GENERIC_READ,
423         DWORD dwFlags = FTP_TRANSFER_TYPE_BINARY, DWORD_PTR dwContext = 1);
424 
425 #if _WIN32_IE >= 0x0500
426     CInternetFile* Command(LPCTSTR pszCommand, CmdResponseType eResponse = CmdRespNone,
427         DWORD dwFlags = FTP_TRANSFER_TYPE_BINARY,
428         DWORD_PTR dwContext = 1);
429 #endif
430 
431 // Implementation
432     ~CFtpConnection();
433 
434 protected:
435     CString m_strServerName;
436 
437 public:
438 #ifdef _DEBUG
439     virtual void Dump(CDumpContext& dc) const;
440     virtual void AssertValid() const;
441 #endif
442 
443     DECLARE_DYNAMIC(CFtpConnection)
444 };
445 
446 class CHttpConnection : public CInternetConnection
447 {
448 public:
449     enum {
450         _HTTP_VERB_MIN      = 0,
451         HTTP_VERB_POST      = 0,
452         HTTP_VERB_GET       = 1,
453         HTTP_VERB_HEAD      = 2,
454         HTTP_VERB_PUT       = 3,
455         HTTP_VERB_LINK      = 4,
456         HTTP_VERB_DELETE    = 5,
457         HTTP_VERB_UNLINK    = 6,
458         _HTTP_VERB_MAX      = 6,
459     };
460 
461 public:
462     CHttpConnection(CInternetSession* pSession, HINTERNET hConnected,
463         LPCTSTR pstrServer, DWORD_PTR dwContext);
464     CHttpConnection(CInternetSession* pSession, LPCTSTR pstrServer,
465         INTERNET_PORT nPort = INTERNET_INVALID_PORT_NUMBER,
466         LPCTSTR pstrUserName = NULL, LPCTSTR pstrPassword = NULL,
467         DWORD_PTR dwContext = 1);
468     CHttpConnection(CInternetSession* pSession, LPCTSTR pstrServer,
469         DWORD dwFlags, INTERNET_PORT nPort = INTERNET_INVALID_PORT_NUMBER,
470         LPCTSTR pstrUserName = NULL, LPCTSTR pstrPassword = NULL,
471         DWORD_PTR dwContext = 1);
472 
473     CHttpFile* OpenRequest(LPCTSTR pstrVerb,    LPCTSTR pstrObjectName,
474         LPCTSTR pstrReferer = NULL,DWORD_PTR dwContext = 1,
475         LPCTSTR* ppstrAcceptTypes = NULL, LPCTSTR pstrVersion = NULL,
476         DWORD dwFlags = INTERNET_FLAG_EXISTING_CONNECT);
477 
478     CHttpFile* OpenRequest(int nVerb, LPCTSTR pstrObjectName,
479         LPCTSTR pstrReferer = NULL, DWORD_PTR dwContext = 1,
480         LPCTSTR* ppstrAcceptTypes = NULL, LPCTSTR pstrVersion = NULL,
481         DWORD dwFlags = INTERNET_FLAG_EXISTING_CONNECT);
482 
483 // Implementation
484     ~CHttpConnection();
485 
486 protected:
487     CString m_strServerName;
488     static const LPCTSTR szHtmlVerbs[];
489 
490 public:
491 #ifdef _DEBUG
492     virtual void Dump(CDumpContext& dc) const;
493     virtual void AssertValid() const;
494 #endif
495 
496     friend class CInternetSession;  // just to access szHtmlVerbs
497     DECLARE_DYNAMIC(CHttpConnection)
498 };
499 
500 class CGopherConnection : public CInternetConnection
501 {
502 public:
503     CGopherConnection(CInternetSession* pSession,
504         HINTERNET hConnected, LPCTSTR pstrServer, DWORD_PTR dwContext);
505 
506     CGopherConnection(CInternetSession* pSession, LPCTSTR pstrServer,
507         LPCTSTR pstrUserName = NULL, LPCTSTR pstrPassword = NULL,
508         DWORD_PTR dwContext = 0,
509         INTERNET_PORT nPort = INTERNET_INVALID_PORT_NUMBER);
510 
511     CGopherFile* OpenFile(CGopherLocator& refLocator, DWORD dwFlags = 0,
512         LPCTSTR pstrView = NULL, DWORD_PTR dwContext = 1);
513 
514     CGopherLocator CreateLocator(LPCTSTR pstrDisplayString,
515         LPCTSTR pstrSelectorString, DWORD dwGopherType);
516 
517     BOOL CGopherConnection::GetAttribute(CGopherLocator& refLocator,
518         CString strRequestedAttributes, CString& strResult);
519 
520     static CGopherLocator CreateLocator(LPCTSTR pstrLocator);
521     static CGopherLocator CreateLocator(LPCTSTR pstrServerName,
522         LPCTSTR pstrDisplayString,
523         LPCTSTR pstrSelectorString, DWORD dwGopherType,
524         INTERNET_PORT nPort = INTERNET_INVALID_PORT_NUMBER);
525 
526 // Implementation
527     ~CGopherConnection();
528 
529 public:
530 #ifdef _DEBUG
531     virtual void Dump(CDumpContext& dc) const;
532     virtual void AssertValid() const;
533 #endif
534     DECLARE_DYNAMIC(CGopherConnection)
535 };
536 
537 
538 /////////////////////////////////////////////////////////////////////////////
539 // CFtpFileFind
540 
541 class CFtpFileFind : public CFileFind
542 {
543 public:
544     explicit CFtpFileFind(CFtpConnection* pConnection, DWORD_PTR dwContext = 1);
545     virtual ~CFtpFileFind();
546 
547     virtual BOOL FindFile(LPCTSTR pstrName = NULL,
548         DWORD dwFlags = INTERNET_FLAG_RELOAD);
549     virtual BOOL FindNextFile();
550     CString GetFileURL() const;
551 
552 // Implementation
553 protected:
554     virtual void CloseContext();
555     CFtpConnection* m_pConnection;
556     DWORD_PTR m_dwContext;
557 
558 public:
559 #ifdef _DEBUG
560     virtual void Dump(CDumpContext& dc) const;
561     virtual void AssertValid() const;
562 #endif
563 
564     DECLARE_DYNAMIC(CFtpFileFind)
565 };
566 
567 
568 /////////////////////////////////////////////////////////////////////////////
569 // CGopherLocator
570 
571 class CGopherLocator : public CObject
572 {
573 public:
574     ~CGopherLocator();
575     operator LPCTSTR() const;
576     CGopherLocator(const CGopherLocator& ref);
577     BOOL GetLocatorType(DWORD& dwRef) const;
578 
579 private:
580     // this only created by CGopherConnection::CreateLocator or by serialization
581     CGopherLocator(LPCTSTR pstrLocator, DWORD dwLocLen);
582 
583     CString m_Locator;  // _not_ a zero-terminated string!
584     DWORD m_dwBufferLength;
585 
586     friend class CGopherConnection;
587     friend class CGopherFile;
588 };
589 
590 
591 /////////////////////////////////////////////////////////////////////////////
592 // CGopherFile
593 
594 class CGopherFile : public CInternetFile
595 {
596 // Constructors
597 protected:
598     CGopherFile(HINTERNET hFile, CGopherLocator& refLocator,
599         CGopherConnection* pConnection);
600     CGopherFile(HINTERNET hFile, HINTERNET hSession,
601         LPCTSTR pstrLocator, DWORD dwLocLen, DWORD_PTR dwContext);
602 
603 // Operations
604 public:
605     virtual void Write(const void* lpBuf, UINT nCount);
606     void WriteString(LPCTSTR pstr);
607 
608 // Implementation
609 protected:
610     CGopherLocator m_Locator;
611 public:
612     virtual ~CGopherFile();
613 
614 #ifdef _DEBUG
615     virtual void AssertValid() const;
616     virtual void Dump(CDumpContext& dc) const;
617 #endif
618 
619     friend class CInternetSession;
620     friend class CGopherConnection;
621     DECLARE_DYNAMIC(CGopherFile)
622 };
623 
624 
625 /////////////////////////////////////////////////////////////////////////////
626 // CGopherFileFind
627 
628 class CGopherFileFind : public CFileFind
629 {
630 public:
631     explicit CGopherFileFind(CGopherConnection* pConnection, DWORD_PTR dwContext = 1);
632     virtual ~CGopherFileFind();
633 
634     virtual BOOL FindFile(CGopherLocator& refLocator, LPCTSTR pstrString,
635         DWORD dwFlags = INTERNET_FLAG_RELOAD);
636     virtual BOOL FindFile(LPCTSTR pstrString,
637         DWORD dwFlags = INTERNET_FLAG_RELOAD);
638     virtual BOOL FindNextFile();
639 
640     virtual BOOL IsDots() const;
641 
642     virtual BOOL GetLastWriteTime(FILETIME* pTimeStamp) const;
643     virtual BOOL GetLastAccessTime(FILETIME* pTimeStamp) const;
644     virtual BOOL GetCreationTime(FILETIME* pTimeStamp) const;
645     virtual BOOL GetLastWriteTime(CTime& refTime) const;
646     virtual BOOL GetLastAccessTime(CTime& refTime) const;
647     virtual BOOL GetCreationTime(CTime& refTime) const;
648 
649     CGopherLocator GetLocator() const;
650     CString GetScreenName() const;
651 
652     virtual ULONGLONG GetLength() const;
653 
654 protected:
655     virtual void CloseContext();
656     CGopherConnection* m_pConnection;
657     DWORD_PTR m_dwContext;
658 
659 // Implementation
660 public:
661     // Unsupported APIs
662     CString GetFileName() const;
663     CString GetFilePath() const;
664     CString GetFileTitle() const;
665     CString GetFileURL() const;
666     CString GetRoot() const;
667 
668 #ifdef _DEBUG
669     virtual void Dump(CDumpContext& dc) const;
670     virtual void AssertValid() const;
671 #endif
672     DECLARE_DYNAMIC(CGopherFileFind)
673 };
674 
675 
676 ///////////////////////////////////////////////////////////////////////
677 // CInternetException
678 
679 class CInternetException : public CException
680 {
681 public:
682 // Constructor
683     CInternetException(DWORD dwError);
684 
685 // Attributes
686     DWORD m_dwError;
687     DWORD_PTR m_dwContext;
688 
689 // Implementation
690 public:
691     ~CInternetException();
692 #ifdef _DEBUG
693     virtual void Dump(CDumpContext& dc) const;
694 #endif
695     virtual BOOL GetErrorMessage(_Out_z_cap_(nMaxError) LPTSTR lpstrError, _In_ UINT nMaxError,
696         _Out_opt_ PUINT pnHelpContext = NULL) const;
697     DECLARE_DYNAMIC(CInternetException)
698 };
699 
700 /////////////////////////////////////////////////////////////////////////////
701 // Inline function declarations
702 
703 #ifdef _AFX_ENABLE_INLINES
704 #define _AFXINET_INLINE AFX_INLINE
705 #include <afxinet.inl>
706 #endif
707 
708 #undef AFX_DATA
709 #define AFX_DATA
710 
711 #ifdef _AFX_MINREBUILD
712 #pragma component(minrebuild, on)
713 #endif
714 
715 #ifndef _AFX_DISABLE_DEPRECATED
716 #pragma deprecated( CGopherLocator )
717 #pragma deprecated( CGopherFile )
718 #pragma deprecated( CGopherConnection )
719 #pragma deprecated( CGopherFileFind )
720 #endif
721 
722 #endif // __AFXINET_H__
Afxinet.h

头文件DataBaseSink.h :

bubuko.com,布布扣
  1 #ifndef DATA_BASE_SINK_HEAD_FILE
  2 #define DATA_BASE_SINK_HEAD_FILE
  3 
  4 #pragma once
  5 
  6 #include "Stdafx.h"
  7 #include "GameServiceExport.h"
  8 
  9 //////////////////////////////////////////////////////////////////////////
 10 //结构定义
 11 
 12 //数据库参数
 13 struct tagDataBaseSinkParameter
 14 {
 15     tagDataBaseInfo                        * pGameUserDBInfo;                //连接信息
 16     tagDataBaseInfo                        * pGameScoreDBInfo;                //连接信息
 17     tagGameServiceAttrib                * pGameServiceAttrib;            //服务属性
 18     tagGameServiceOption                * pGameServiceOption;            //配置信息
 19 };
 20 
 21 //////////////////////////////////////////////////////////////////////////
 22 //数据库请求数据包
 23 
 24 //数据库请求标识
 25 #define    DBR_GR_LOGON_BY_USERID            1                                //I D 登录
 26 #define DBR_GR_WRITE_GAME_SCORE            2                                //离开房间
 27 #define DBR_GR_LEAVE_GAME_SERVER        3                                //修改积分
 28 #define DBR_GR_GAME_SCORE_RECORD        4                                //积分记录
 29 #define DBR_GR_GAME_DETAILS_RECORD        5                                //积分记录
 30 #define DBR_GR_LOAD_ANDROID                6                                //加载用户
 31 #define DBR_GR_LIMIT_ACCOUNTS            7                                //禁用帐户
 32 #define DBR_GR_SET_USER_RIGHT            8                                //设置权限
 33 #define DBR_GR_UNLOCK_BY_USERID            9                                //解锁用户
 34 
 35 #define DBR_GR_SEND_GIFT                10                                //赠送礼物
 36 #define DBR_GR_BUY_PROPERTY                11                                //道具消息
 37 #define DBR_GR_LOAD_PROPERTY            12                                //下载道具
 38 #define DBR_GR_WRITE_PROPERTY            13                                //写入结果
 39 
 40 #define DBR_GR_BANK_GET_GOLD            14                                //提取金币
 41 #define DBR_GR_BANK_STORAGE_GOLD        15                                //存储金币
 42 
 43 
 44 //数据库输出标识
 45 #define DBR_GR_LOGON_SUCCESS            100                                //登录成功
 46 #define DBR_GR_LOGON_ERROR                101                                //登录失败
 47 #define DBR_GR_READ_ANDROID_SUCCESS        102                                //机器信息
 48 #define DBR_GR_READ_ANDROID_FINISH      103                             //机器人读取结束
 49 
 50 //ID 登录
 51 struct DBR_GR_LogonByUserID
 52 {
 53     DWORD                                dwUserID;                        //用户 I D
 54     DWORD                                dwClientIP;                        //连接地址
 55     TCHAR                                szPassWord[PASS_LEN];            //登录密码
 56     TCHAR                                szComputerID[COMPUTER_ID_LEN];    //机器序列
 57 };
 58 
 59 //禁用帐户
 60 struct DBR_GR_LimitAccounts
 61 {
 62     DWORD                                dwUserID;                        //用户 I D
 63 };
 64 
 65 //设置权限
 66 struct DBR_GR_SetUserRight
 67 {
 68     //权限范围
 69     BYTE                                cbGame;                            //设置游戏
 70     BYTE                                cbAccounts;                        //设置帐号
 71 
 72     //权限信息
 73     DWORD                                dwUserID;                        //用户 I D
 74     DWORD                                dwUserRight;                    //用户权限
 75     DWORD                                dwMasterUserID;                    //管理 I D
 76     DWORD                                dwMasterClientIP;                //连接地址
 77 };
 78 
 79 //机器用户
 80 struct DBO_GR_AndroidUser
 81 {
 82     LONG                                lResultCode;                    //结果代码
 83     WORD                                wAndroidCount;                    //用户数目
 84     DWORD                                dwAndroidID[MAX_ANDROID];        //用户 I D
 85     WORD                                dwAndroidType[MAX_ANDROID];        //机器人类别:0陪玩,1占座,其余未使用
 86 };
 87 
 88 //ID 解锁用户
 89 struct DBR_GR_UnLockByUserID
 90 {
 91     DWORD                                dwUserID;                        //用户 I D
 92 };
 93 
 94 //登录成功
 95 struct DBR_GR_LogonSuccess
 96 {
 97     //基本信息
 98     WORD                                wFaceID;                        //头像索引
 99     DWORD                                dwUserID;                        //用户 I D
100     DWORD                                dwGameID;                        //用户 I D
101     DWORD                                dwGroupID;                        //社团索引
102     DWORD                                dwUserRight;                    //用户等级
103     DWORD                                dwMasterRight;                    //管理权限
104 
105     BYTE                                bVip;                            //VIP用户标识
106     BOOL                                bAIFlage;                       //机器人用户标识
107     WORD                                wAIType;                        //机器人类别:0陪玩,1占座,其余未使用
108 
109     //用户属性
110     BYTE                                cbGender;                        //用户性别
111     BYTE                                cbMasterOrder;                    //管理等级
112     BYTE                                cbMemberOrder;                    //会员等级
113 
114     //积分信息
115     LONG                                lScore;                            //用户分数
116     LONG                                lGold;                            //用户元宝
117     LONG                                lPaiCoin;                        //用户拍币
118     LONG                                lExperience;                    //用户经验
119     LONG                                lWinCount;                        //胜利盘数
120     LONG                                lLostCount;                        //失败盘数
121     LONG                                lDrawCount;                        //和局盘数
122     LONG                                lFleeCount;                        //断线数目
123 
124     TCHAR                                szAccounts[NAME_LEN];            //登录帐号
125     TCHAR                                szNickname[NAME_LEN];            //用户昵称
126     TCHAR                                szPassWord[PASS_LEN];            //登录密码
127     TCHAR                                szGroupName[GROUP_LEN];            //社团名字
128     TCHAR                                szUnderWrite[UNDER_WRITE_LEN];    //个性签名
129     TCHAR                                szLognoIP[COMPUTER_ID_LEN];        //IP登陆地址
130 };
131 
132 //登录失败
133 struct DBR_GR_LogonError
134 {
135     LONG                                lErrorCode;                        //错误代码
136     TCHAR                                szErrorDescribe[128];            //错误消息
137 };
138 
139 //修改积分
140 struct DBR_GR_WriteUserScore
141 {
142     //用户属性
143     DWORD                                dwUserID;                        //用户地址
144     DWORD                                dwClientIP;                        //连接地址
145     DWORD                                dwPlayTimeCount;                //游戏时间
146     DWORD                                dwOnlineTimeCount;                //在线时间
147 
148     //积分信息
149     LONG                                lRevenue;                        //游戏税收
150     tagUserScore                        ScoreModifyInfo;                //修改积分
151 };
152 
153 //离开房间
154 struct DBR_GR_LeaveGameServer
155 {
156     //用户属性
157     DWORD                                dwUserID;                        //用户地址
158     DWORD                                dwClientIP;                        //连接地址
159     DWORD                                dwPlayTimeCount;                //游戏时间
160     DWORD                                dwOnlineTimeCount;                //在线时间
161 
162     //积分信息
163     LONG                                lRevenue;                        //游戏税收
164     tagUserScore                        ScoreModifyInfo;                //修改积分
165 };
166 
167 //////////////////////////////////////////////////////////////////////////
168 
169 //数据库引擎钩子
170 class CDataBaseSink : public IDataBaseSink
171 {
172     //配置变量
173 protected:
174     tagDataBaseInfo                        * m_pGameUserDBInfo;            //连接信息
175     tagDataBaseInfo                        * m_pGameScoreDBInfo;            //连接信息
176     tagGameServiceAttrib                * m_pGameServiceAttrib;            //服务属性
177     tagGameServiceOption                * m_pGameServiceOption;            //配置信息
178     CStringArray                        tempIP;                            //临时IP
179 
180     //接口变量
181 protected:
182     IEventService                        * m_pIEventService;                //事件服务
183 
184     //组件变量
185 protected:
186     CDataBaseHelper                        m_GameUserDB;                    //用户数据库
187     CDataBaseHelper                        m_GameScoreDB;                    //游戏数据库
188     CQueueServiceEvent                    m_AttemperEvent;                //调度通知
189 
190     //函数定义
191 public:
192     //构造函数
193     CDataBaseSink();
194     //析构函数
195     virtual ~CDataBaseSink();
196 
197     //基础接口
198 public:
199     //释放对象
200     virtual bool __cdecl Release() { if (IsValid()) delete this; return true; }
201     //是否有效
202     virtual bool __cdecl IsValid() { return AfxIsValidAddress(this,sizeof(CDataBaseSink))?true:false; }
203     //接口查询
204     virtual void * __cdecl QueryInterface(const IID & Guid, DWORD dwQueryVer);
205 
206     //调度接口
207 public:
208     //调度模块启动
209     virtual bool __cdecl StartService(IUnknownEx * pIUnknownEx);
210     //调度模块关闭
211     virtual bool __cdecl StopService(IUnknownEx * pIUnknownEx);
212     //数据操作处理
213     virtual bool __cdecl OnDataBaseRequest(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize);
214 
215     //配置函数 
216 public:
217     //设置事件
218     bool SetEventService(IUnknownEx * pIUnknownEx);
219     //配置函数
220     bool InitDataBaseSink(tagDataBaseSinkParameter * pDataBaseSinkParameter, IUnknownEx * pIUnknownEx);
221 
222     //处理函数
223 private:
224     //登录请求
225     bool OnRequestLogon(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize);
226     //写分请求
227     bool OnRequestWriteUserScore(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize);
228     //离开房间
229     bool OnRequestLeaveGameServer(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize);
230     //禁用帐户
231     bool OnRequestLimitAccounts(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize);
232     //设置权限
233     bool OnRequestSetUserRight(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize);
234     //记录游戏
235     bool OnRequestRecordGameDetails(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize);
236     //装载机器人
237     bool OnRequestReadAIUser(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize);
238     //解锁用户
239     bool OnRequestUnLockUser(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize);
240     //赠送金钱
241     bool OnRequestGiveMoney(const NTY_DataBaseEvent & DataBaseEvent, void * pDataBuffer, WORD wDataSize);
242 
243     //存储过程
244 protected:
245     //I D 存储过程
246     LONG SPLogonByUserID(DWORD dwUserID, LPCTSTR pszPassword, DWORD dwClientIP, LPCTSTR pszComputerID);
247     //写分存储过程
248     LONG SPWriteUserScore(DWORD dwUserID, DWORD dwPlayTimeCount, DWORD dwOnLineTimeCount, DWORD dwClientIP, LONG lRevenue, tagUserScore & UserScore);
249     //离开存储过程
250     LONG SPLeaveGameServer(DWORD dwUserID, DWORD dwPlayTimeCount, DWORD dwOnLineTimeCount, DWORD dwClientIP, LONG lRevenue, tagUserScore & UserScore);
251     //禁号存储过程
252     LONG SPCongealAccounts(DWORD dwUserID);
253     //权限存储过程
254     LONG SPSetUserGameRight(DWORD dwUserID, DWORD dwUserRight, DWORD dwMasterUserID, DWORD dwClientIP);
255     //权限存储过程
256     LONG SPSetUserAccountsRight(DWORD dwUserID, DWORD dwUserRight, DWORD dwMasterUserID, DWORD dwClientIP);
257     //加载机器人存储过程
258     LONG SPLoadAndroidUser(WORD wKindID, WORD wServerID);
259     //加载机器人详细信息存储过程
260     LONG SPLoadAndroidUserLogon(DWORD dwUserID, WORD wKindID, WORD wServerID);
261     //重置机器人修改触发字段
262     LONG SPResetChanged(WORD wKindID, WORD wServerID);
263     //重置程序异常触发修改触发字段
264     LONG SPResetAbnormity(WORD wKindID, WORD wServerID);
265 };
266 
267 //////////////////////////////////////////////////////////////////////////
268 
269 #endif
DataBaseSink.h

头文件GameServiceExport.h :

bubuko.com,布布扣
  1 #ifndef GAME_SERVICE_EXPORT_HEAD_FILE
  2 #define GAME_SERVICE_EXPORT_HEAD_FILE
  3 
  4 //////////////////////////////////////////////////////////////////////////
  5 
  6 //平台头文件
  7 #include "..\..\Include\模板库\Template.h"
  8 #include "..\..\Include\公共文件\GlobalDef.h"
  9 #include "..\..\Include\公共文件\GlobalField.h"
 10 #include "..\..\Include\公共文件\GlobalFrame.h"
 11 #include "..\..\Include\公共文件\GlobalRight.h"
 12 #include "..\..\Include\公共文件\GlobalService.h"
 13 
 14 //命令码文件
 15 #include "..\..\Include\消息定义\CMD_Game.h"
 16 #include "..\..\Include\消息定义\CMD_Video.h"
 17 #include "..\..\Include\消息定义\CMD_Plaza.h"
 18 #include "..\..\Include\消息定义\CMD_Center.h"
 19 
 20 //组件头文件
 21 #include "..\..\Include\组件接口\IUnknownEx.h"
 22 #include "..\..\共享组件\网络组件\SocketModule.h"
 23 #include "..\..\服务器组件\内核组件\ServerKernel.h"
 24 
 25 //////////////////////////////////////////////////////////////////////////
 26 //公共宏定义
 27 
 28 //导出定义
 29 #ifndef GAME_SERVICE_CLASS
 30     #ifdef  GAME_SERVICE_DLL
 31         #define GAME_SERVICE_CLASS _declspec(dllexport)
 32     #else
 33         #define GAME_SERVICE_CLASS _declspec(dllimport)
 34     #endif
 35 #endif
 36 
 37 //模块定义
 38 #ifdef _DEBUG
 39     #define GAME_SERVICE_DLL_NAME    TEXT("GameCommonD.dll")                //组件 DLL 名字
 40 #else
 41     #define GAME_SERVICE_DLL_NAME    TEXT("GameCommon.dll")                //组件 DLL 名字
 42 #endif
 43 
 44 //////////////////////////////////////////////////////////////////////////
 45 
 46 //宏定义
 47 #define IDI_MAX_TIME_ID                    30                                    //极限定时器
 48 
 49 //结束原因
 50 #define GER_NORMAL                        0x00                                //常规结束
 51 #define GER_DISMISS                        0x01                                //游戏解散
 52 #define GER_USER_LEFT                    0x02                                //用户离开
 53 
 54 //索引定义
 55 #define INDEX_SOCKET                    (WORD)(0x0000)                        //网络索引
 56 #define INDEX_ANDROID                    (WORD)(0x2000)                        //机器索引
 57 #define INVALID_WORD_INDEX                (WORD)(0xFFFF)                        //无效索引
 58 
 59 //////////////////////////////////////////////////////////////////////////
 60 //调度时间
 61 
 62 //时间范围
 63 #define IDI_ATTEMPER_START                1                                    //调度起始
 64 #define IDI_ATTEMPER_CONCLUDE            99                                    //调度结束
 65 
 66 //时间标识
 67 #define IDI_CONNECT_CENTER_SERVER        (IDI_ATTEMPER_START+1)                //连接服务器
 68 #define IDI_UPDATE_SERVER_LIST            (IDI_ATTEMPER_START+2)                //更新列表
 69 #define IDI_UPDATE_ONLINE_COUNT            (IDI_ATTEMPER_START+3)                //更新人数
 70 #define IDI_SEND_SYSTEM_MESSAGE            (IDI_ATTEMPER_START+4)                //系统消息
 71 
 72 //机器标识
 73 #define IDI_AI_USER_RANDOPERATION        (IDI_ATTEMPER_START+5)                //机器人随机动作
 74 #define IDI_AI_TABLE_RANDOPERATION        (IDI_ATTEMPER_START+6)                //游戏桌随机动作
 75 #define IDI_DISTRIBUTE_ANDROID            (IDI_ATTEMPER_START+7)                //分配用户(待使用)
 76 
 77 //时间定义
 78 #define TIME_RECONNECT                    15000L                                //重连时间
 79 #define TIME_UPDATE_LIST                30000L                                //更新时间
 80 #define TIME_UPDATE_ONLINE                30000L                                //更新人数
 81 
 82 //////////////////////////////////////////////////////////////////////////
 83 //机器时间
 84 
 85 //时间范围
 86 #define IDI_ANDROID_START                100                                    //机器起始
 87 #define IDI_ANDROID_CONCLUDE            199                                    //机器结束
 88 
 89 //时间标识
 90 #define IDI_ANDROID_INOUT                (IDI_ANDROID_START+1)                //进出时间
 91 #define IDI_ANDROID_USER_PULSE            (IDI_ANDROID_START+2)                //脉冲时间
 92 
 93 //机器时间
 94 #define IDI_ANDROID_USER_TIEM            1                                    //起始标识
 95 #define IDI_ANDROID_ITEM_SINK            500                                    //起始标识
 96 
 97 //辅助时间
 98 #define TIME_LOAD_ANDROID_INFO            180L                                //加载用户
 99 #define TIME_DISTRIBUTE_ANDROID            15L                                    //分配用户
100 
101 //用户时间
102 #define TIME_ANDROID_INOUT                10L                                    //登录时间
103 #define TIME_ANDROID_SERVICE            7200L                                //服务时间
104 #define TIME_ANDROID_USER_PULSE            1L                                    //用户脉冲
105 
106 //////////////////////////////////////////////////////////////////////////
107 //桌子时间
108 
109 //时间范围
110 #define IDI_TABLE_FRAME_START            200                                    //桌子起始
111 #define IDI_TABLE_FRAME_CONCLUDE        5000                                //桌子结束
112 
113 //时间常量
114 #define RANGE_TABLE_TIME                50                                    //标识范围
115 
116 //服务器单元积分与游戏积分比例
117 #define GAME_CELL_INVERSE                    100                               //单元积分比例
118 
119 //////////////////////////////////////////////////////////////////////////
120 //枚举定义
121 
122 //开始模式
123 enum enStartMode
124 {
125     enStartMode_FullReady,                //满人开始
126     enStartMode_AllReady,                //所有准备
127     enStartMode_Symmetry,                //对称开始
128     enStartMode_TimeControl,            //时间控制
129 };
130 
131 //分数类型
132 enum enScoreKind
133 {
134     enScoreKind_Win,                    //
135     enScoreKind_Lost,                    //
136     enScoreKind_Draw,                    //
137     enScoreKind_Flee,                    //
138     enScoreKind_Service,                //服务
139     enScoreKind_Present,                //赠送
140     enScoreKind_Contribute,                //贡献
141 };
142 
143 //////////////////////////////////////////////////////////////////////////
144 //结构定义
145 
146 //积分信息
147 struct tagScoreInfo
148 {
149     LONG                                lScore;                                //游戏积分
150     LONG                                lGold;                                //游戏元宝
151     LONG                                lRevenue;                            //游戏税收
152     enScoreKind                            ScoreKind;                            //分数类型
153 };
154 
155 //记录游戏
156 struct tagRecordGameDetails
157 {
158     DWORD                                dwUserID;                        //用户 I D
159     DWORD                                dwKindID;                        //游戏 I D
160     DWORD                                dwStartTime;                    //开始时间
161     DWORD                                dwEndTime;                        //结束时间
162     LONG                                lScore;                            //积分
163     LONG                                lGold;                            //游戏积分
164     LONG                                lRevenue;                       //税收
165     TCHAR                                szDetails[DETAILS_LEN];            //详细
166     //DOUBLE                                dCellScore;                        //单元积分
167 };
168 
169 
170 //用户规则
171 struct tagUserRule
172 {
173     bool                                bPassword;                            //设置密码
174     bool                                bLimitWin;                            //限制胜率
175     bool                                bLimitFlee;                            //限制逃跑
176     bool                                bLimitScore;                        //限制分数
177     bool                                bCheckSameIP;                        //效验地址
178     WORD                                wWinRate;                            //胜率限制
179     WORD                                wFleeRate;                            //限制逃跑
180     LONG                                lMaxScore;                            //最高分数 
181     LONG                                lLessScore;                            //最低分数
182     TCHAR                                szPassword[PASS_LEN];                //桌子密码
183 };
184 
185 struct tagProperty 
186 { 
187     INT                                    nPropertyID;                        //道具ID 
188     DWORD                                dwPropertyCount;                    //可用数目 
189     DWORD                                dwConsumedCount;                    //使用数目 
190 }; 
191 
192 
193 //用户信息结构
194 struct tagServerUserData
195 {
196     //属性信息
197     WORD                                wFaceID;                            //头像索引
198     DWORD                                dwUserID;                            //用户 I D
199     DWORD                                dwGameID;                            //游戏 I D
200     DWORD                                dwGroupID;                            //社团索引
201     DWORD                                dwUserRight;                        //用户等级
202     DWORD                                dwMasterRight;                        //管理权限
203     TCHAR                                szAccounts[NAME_LEN];                //用户帐号
204     TCHAR                                szNickname[NAME_LEN];                //用户帐号
205     TCHAR                                szGroupName[GROUP_LEN];                //社团名字
206     TCHAR                                szUnderWrite[UNDER_WRITE_LEN];        //个性签名
207     BYTE                                bVip;                                //VIP用户标识
208 
209     BOOL                                bAIFlag;                            //机器人用户标识
210     WORD                                wAIType;                        //机器人类别:0陪玩,1占座,2赢钱 其余未使用
211 
212     //用户属性
213     BYTE                                cbGender;                            //用户性别
214     BYTE                                cbMemberOrder;                        //会员等级
215     BYTE                                cbMasterOrder;                        //管理等级
216 
217     //分数信息
218     LONG                                lStorageScore;                        //存储积分
219     tagUserScore                        UserScoreInfo;                        //用户分数
220     tagUserStatus                        UserStatus;
221     //tagProperty                            PropertyInfo[PROPERTY_COUNT];        //道具信息 
222 
223     TCHAR                                sdLognoIP[COMPUTER_ID_LEN];           //IP登陆地址
224 };
225 
226 //桌子参数结构
227 struct tagTableFrameParameter
228 {
229     IUnknownEx                            * pIGameServiceFrame;                //服务框架
230     IUnknownEx                            * pIGameServiceManager;                //服务管理
231     const tagGameServiceAttrib            * pGameServiceAttrib;                //桌子属性
232     const tagGameServiceOption            * pGameServiceOption;                //配置参数
233 };
234 
235 //服务参数结构
236 struct tagGameServiceParameter
237 {
238     TCHAR                                szModule[32];                        //模块名字
239     DWORD                                dwCenterAddr;                        //中心地址
240     tagDataBaseInfo                        GameUserDBInfo;                        //数据配置
241     tagDataBaseInfo                        GameScoreDBInfo;                    //数据配置
242     tagGameServiceOption                GameServiceOption;                    //服务配置
243 };
244 
245 //////////////////////////////////////////////////////////////////////////
246 
247 #ifdef _UNICODE
248     #define VER_IServerUserItem INTERFACE_VERSION(5,2)
249     static const GUID IID_IServerUserItem={0x0400256a,0x6287,0x4a82,0x92,0xbf,0x53,0xcf,0x51,0x62,0x76,0x21};
250 #else
251     #define VER_IServerUserItem INTERFACE_VERSION(5,2)
252     static const GUID IID_IServerUserItem={0xe4ce78b7,0x9758,0x4b85,0xa5,0xa9,0x75,0x2f,0x66,0x63,0x32,0x5a};
253 #endif
254 
255 //服务器用户接口
256 interface IServerUserItem : public IUnknownEx
257 {
258     //信息接口
259 public:
260     //是否激活
261     virtual bool __cdecl IsActive()=NULL;
262     //用户索引
263     virtual WORD __cdecl GetUserIndex()=NULL;
264     //获取地址
265     virtual DWORD __cdecl GetClientIP()=NULL;
266     //获取密码
267     virtual LPCTSTR __cdecl GetPassword()=NULL;
268     //获取规则
269     virtual const tagUserRule * __cdecl GetUserRule()=NULL;
270     //获取积分
271     virtual const tagUserScore * __cdecl GetUserScore()=NULL;
272     //获取信息
273     virtual tagServerUserData * __cdecl GetUserData()=NULL;
274     //判断机器人
275     virtual bool __cdecl IsAIUser()=NULL;
276     //判断机器人
277     virtual bool __cdecl IsVIPUser()=NULL;
278 
279     //属性接口
280 public:
281     //用户名字
282     virtual LPCTSTR __cdecl GetAccounts()=NULL;
283     //用户 I D
284     virtual DWORD __cdecl GetUserID()=NULL;
285     //桌子号码
286     virtual WORD __cdecl GetTableID()=NULL;
287     //椅子号码
288     virtual WORD __cdecl GetChairID()=NULL;
289     //用户状态
290     virtual BYTE __cdecl GetUserStatus()=NULL;
291     //用户胜率
292     virtual WORD __cdecl GetUserWinRate()=NULL;
293     //用户输率
294     virtual WORD __cdecl GetUserLostRate()=NULL;
295     //用户和率
296     virtual WORD __cdecl GetUserDrawRate()=NULL;
297     //用户逃率
298     virtual WORD __cdecl GetUserFleeRate()=NULL;
299 
300     //统计接口
301 public:
302     //游戏时间
303     virtual DWORD __cdecl GetPlayTimeCount()=NULL;
304     //在线时间
305     virtual DWORD __cdecl GetOnlineTimeCount()=NULL;
306 
307     //功能接口
308 public:
309     //设置规则
310     virtual bool __cdecl SetUserRule(tagUserRule & UserRule)=NULL;
311     //积分信息
312     virtual bool __cdecl GetUserScoreInfo(tagUserScore & ScoreModifyInfo)=NULL;
313     //修改积分
314     virtual bool __cdecl WriteScore(tagScoreInfo & ScoreInfo, DWORD dwPlayTimeCount)=NULL;
315     //设置状态
316     virtual bool __cdecl SetUserStatus(BYTE cbUserStatus, WORD wTableID, WORD wChairID)=NULL;
317 
318 };
319 
320 //////////////////////////////////////////////////////////////////////////
321 
322 #ifdef _UNICODE
323     #define VER_IServerUserManager INTERFACE_VERSION(5,2)
324     static const GUID IID_IServerUserManager={0x580b63b7,0x4b4f,0x4c6d,0xb7,0x49,0x5b,0x9f,0x46,0xc6,0x36,0xee};
325 #else
326     #define VER_IServerUserManager INTERFACE_VERSION(5,2)
327     static const GUID IID_IServerUserManager={0x8614dbc0,0xee75,0x4a82,0xb8,0xe1,0xdf,0x22,0x41,0x39,0x6f,0x49};
328 #endif
329 
330 //服务器用户管理接口
331 interface IServerUserManager : public IUnknownEx
332 {
333     //管理接口
334 public:
335     //重置用户
336     virtual bool __cdecl ResetUserManager()=NULL;
337     //切换用户
338     virtual bool __cdecl SwitchOnLineUserItem(IServerUserItem * pIServerUserItem, DWORD dwClientIP, WORD wUserIndex)=NULL;
339     //激活用户
340     virtual bool __cdecl ActiveOffLineUserItem(IServerUserItem * pIServerUserItem, DWORD dwClientIP, WORD wUserIndex)=NULL;
341     //激活用户
342     virtual IServerUserItem * __cdecl ActiveUserItem(tagServerUserData & ServerUserData, DWORD dwClientIP, WORD wUserIndex, TCHAR szPassword[PASS_LEN])=NULL;
343     //删除用户
344     virtual bool __cdecl DeleteUserItem(IServerUserItem * pIServerUserItem)=NULL;
345     //注册断线
346     virtual bool __cdecl RegOffLineUserItem(IServerUserItem * pIServerUserItem)=NULL;
347     //删除断线
348     virtual bool __cdecl UnRegOffLineUserItem(IServerUserItem * pIServerUserItem)=NULL;
349 
350     //查找接口
351 public:
352     //枚举用户
353     virtual IServerUserItem * __cdecl EnumOnLineUser(WORD wEnumIndex)=NULL;
354     //枚举用户
355     virtual IServerUserItem * __cdecl EnumOffLineUser(WORD wEnumIndex)=NULL;
356     //查找用户
357     virtual IServerUserItem * __cdecl SearchOnLineUser(DWORD dwUserID)=NULL;
358     //查找用户
359     virtual IServerUserItem * __cdecl SearchOffLineUser(DWORD dwUserID)=NULL;
360 
361     //信息接口
362 public:
363     //在线人数
364     virtual DWORD __cdecl GetOnLineCount()=NULL;
365     //断线人数
366     virtual DWORD __cdecl GetOffLineCount()=NULL;
367 };
368 
369 //////////////////////////////////////////////////////////////////////////
370 
371 #ifdef _UNICODE
372     #define VER_ITableFrame INTERFACE_VERSION(5,2)
373     static const GUID IID_ITableFrame={0x2b4e7113,0xdf01,0x4398,0xac,0xe0,0x51,0x7f,0x0a,0x60,0xea,0xfd};
374 #else
375     #define VER_ITableFrame INTERFACE_VERSION(5,2)
376     static const GUID IID_ITableFrame={0xe65d2d8c,0xe55a,0x4b7c,0x8d,0xde,0x43,0xcc,0x69,0xdf,0x0f,0x9f};
377 #endif
378 
379 //游戏桌子接口
380 interface ITableFrame : public IUnknownEx
381 {
382     //信息接口
383 public:
384     //桌子号码
385     virtual WORD __cdecl GetTableID()=NULL;
386     //游戏人数
387     virtual WORD __cdecl GetChairCount()=NULL;
388     //游戏时间
389     virtual DWORD __cdecl GetPlayTimeCount()=NULL;
390 
391     //用户接口
392 public:
393     //枚举用户
394     virtual IServerUserItem * __cdecl EnumLookonUserItem(WORD wIndex)=NULL;
395     //获取用户
396     virtual IServerUserItem * __cdecl GetServerUserItem(WORD wChairID)=NULL;
397 
398     //状态接口
399 public:
400     //获取状态
401     virtual BYTE __cdecl GetGameStatus()=NULL;
402     //设置状态
403     virtual void __cdecl SetGameStatus(BYTE bGameStatus)=NULL;
404     //获取配置
405     virtual const tagGameServiceOption * __cdecl GetGameServiceOption()=NULL;
406 
407     //定时器接口
408 public:
409     //设置定时器
410     virtual bool __cdecl SetGameTimer(WORD wTimerID, DWORD dwElapse, DWORD dwRepeat, WPARAM wBindParam)=NULL;
411     //删除定时器
412     virtual bool __cdecl KillGameTimer(WORD wTimerID)=NULL;
413 
414     //AI信息接口
415 public:
416     //获取AI对杀的普通玩家座号码
417     virtual WORD __cdecl GetAIKillGameUserChairID()=NULL;
418     //是否AI对杀普通玩家
419     virtual bool __cdecl IsAIKillGameUser()=NULL; 
420 
421     //网络接口
422 public:
423     //发送数据
424     virtual bool __cdecl SendUserData(IServerUserItem * pIServerUserItem, WORD wSubCmdID)=NULL;
425     //发送数据
426     virtual bool __cdecl SendUserData(IServerUserItem * pIServerUserItem, WORD wSubCmdID, void * pData, WORD wDataSize)=NULL;
427     //发送数据
428     virtual bool __cdecl SendTableData(WORD wChairID, WORD wSubCmdID)=NULL;
429     //发送数据
430     virtual bool __cdecl SendTableData(WORD wChairID, WORD wSubCmdID, void * pData, WORD wDataSize)=NULL;
431     //发送数据
432     virtual bool __cdecl SendLookonData(WORD wChairID, WORD wSubCmdID)=NULL;
433     //发送数据
434     virtual bool __cdecl SendLookonData(WORD wChairID, WORD wSubCmdID, void * pData, WORD wDataSize)=NULL;
435 
436     //消息接口
437 public:
438     //发送房间消息
439     virtual bool __cdecl SendRoomMessage(IServerUserItem * pIServerUserItem, LPCTSTR lpszMessage, WORD wMessageType)=NULL;
440     //发送游戏消息
441     virtual bool __cdecl SendGameMessage(IServerUserItem * pIServerUserItem, LPCTSTR lpszMessage, WORD wMessageType)=NULL;
442 
443     //游戏接口
444 public:
445     //解散游戏
446     virtual bool __cdecl DismissGame()=NULL;
447     //结束游戏
448     virtual bool __cdecl ConcludeGame()=NULL;
449     //发送场景
450     virtual bool __cdecl SendGameScene(IServerUserItem * pIServerUserItem, void * pData, WORD wDataSize)=NULL;
451 
452     //写分接口
453 public:
454     //写入积分
455     virtual bool __cdecl WriteUserScore(WORD wChairID, LONG lScore, LONG lRevenue, LONG lGold, enScoreKind ScoreKind, LONG lTableScore, LPCSTR lpszDetails = NULL)=NULL;
456     //写入积分
457     virtual bool __cdecl WriteUserScore(IServerUserItem * pIServerUserItem, LONG lScore, LONG lRevenue, LONG lGold, enScoreKind ScoreKind)=NULL;
458 };
459 
460 //////////////////////////////////////////////////////////////////////////
461 
462 #ifdef _UNICODE
463     #define VER_ITableFrameManager INTERFACE_VERSION(5,2)
464     static const GUID IID_ITableFrameManager={0xab394013,0x708c,0x4cbe,0xa4,0xa7,0xe1,0x08,0x24,0x3c,0x91,0xdd};
465 #else
466     #define VER_ITableFrameManager INTERFACE_VERSION(5,2)
467     static const GUID IID_ITableFrameManager={0x4dba0eb4,0xd92b,0x471f,0xa5,0x50,0xb4,0xea,0x2a,0x6b,0xca,0x74};
468 #endif
469 
470 //框架管理接口
471 interface ITableFrameManager : public ITableFrame
472 {
473     //配置接口
474 public:
475     //初始化
476     virtual bool __cdecl InitTableFrame(WORD wTableID, tagTableFrameParameter * pTableFrameParameter)=NULL;
477 
478     //信息接口
479 public:
480     //锁定状态
481     virtual bool __cdecl IsTableLocked()=NULL;
482     //游戏状态
483     virtual bool __cdecl IsGameStarted()=NULL;
484     //游戏状态
485     virtual bool __cdecl IsUserPlaying(IServerUserItem * pIServerUserItem)=NULL;
486 
487     //执行接口
488 public:
489     //坐下动作
490     virtual bool __cdecl PerformSitDownAction(WORD wChairID, IServerUserItem * pIServerUserItem)=NULL;
491     //旁观动作
492     virtual bool __cdecl PerformLookonAction(WORD wChairID, IServerUserItem * pIServerUserItem)=NULL;
493     //离开动作
494     virtual bool __cdecl PerformStandUpAction(IServerUserItem * pIServerUserItem)=NULL;
495 
496     //用户事件
497 public:
498     //断线事件
499     virtual bool __cdecl OnUserOffLine(WORD wChairID)=NULL;
500     //重进事件
501     virtual bool __cdecl OnUserReConnect(WORD wChairID)=NULL;
502     //请求断线
503     virtual bool __cdecl OnUserReqOffLine(WORD wChairID)=NULL;
504 
505     //系统事件
506 public:
507     //定时器事件
508     virtual bool __cdecl OnEventTimer(WORD wTimerID, WPARAM wBindParam)=NULL;
509     //游戏事件
510     virtual bool __cdecl OnEventSocketGame(WORD wSubCmdID, const void * pDataBuffer, WORD wDataSize, IServerUserItem * pIServerUserItem)=NULL;
511     //框架事件
512     virtual bool __cdecl OnEventSocketFrame(WORD wSubCmdID, const void * pDataBuffer, WORD wDataSize, IServerUserItem * pIServerUserItem)=NULL;
513     //视频事件处理
514     virtual bool __cdecl OnEventSocketVideo(WORD wSubCmdID, const void * pDataBuffer, WORD wDataSize, IServerUserItem * pIServerUserItem)=NULL;
515 };
516 
517 //////////////////////////////////////////////////////////////////////////
518 
519 #ifdef _UNICODE
520     #define VER_ITableFrameControl INTERFACE_VERSION(5,2)
521     static const GUID IID_ITableFrameControl={0x3d1bbba0,0x9311,0x4dc9,0x97,0x04,0x62,0x36,0xd7,0xa9,0x29,0xb5};
522 #else
523     #define VER_ITableFrameControl INTERFACE_VERSION(5,2)
524     static const GUID IID_ITableFrameControl={0xb2590d93,0xe8fc,0x48fa,0x94,0x44,0x73,0xd8,0x98,0x96,0x88,0x82};
525 #endif
526 
527 //控制接口
528 interface ITableFrameControl : public IUnknownEx
529 {
530     //开始游戏
531     virtual bool __cdecl StartGame()=NULL;
532     //开始判断
533     virtual bool __cdecl StartVerdict()=NULL;
534 };
535 
536 //////////////////////////////////////////////////////////////////////////
537 
538 #ifdef _UNICODE
539     #define VER_ITableFrameSink INTERFACE_VERSION(5,2)
540     static const GUID IID_ITableFrameSink={0xc9aea5dc,0xb7a8,0x47bf,0xb5,0x48,0xcb,0x4b,0xbb,0x3a,0x39,0x6a};
541 #else
542     #define VER_ITableFrameSink INTERFACE_VERSION(5,2)
543     static const GUID IID_ITableFrameSink={0x2b4a4b35,0x837a,0x4e84,0x86,0xcb,0xa0,0x01,0x09,0xa8,0xe9,0x9f};
544 #endif
545 
546 //游戏桌子回调接口
547 interface ITableFrameSink : public IUnknownEx
548 {
549     //管理接口
550 public:
551     //初始化
552     virtual bool __cdecl InitTableFrameSink(IUnknownEx * pIUnknownEx)=NULL;
553     //复位桌子
554     virtual void __cdecl RepositTableFrameSink()=NULL;
555 
556     //信息接口
557 public:
558     //开始模式
559     virtual enStartMode __cdecl GetGameStartMode()=NULL;
560     //游戏状态
561     virtual bool __cdecl IsUserPlaying(WORD wChairID)=NULL;
562 
563     //游戏事件
564 public:
565     //游戏开始
566     virtual bool __cdecl OnEventGameStart()=NULL;
567     //游戏结束
568     virtual bool __cdecl OnEventGameEnd(WORD wChairID, IServerUserItem * pIServerUserItem, BYTE cbReason)=NULL;
569     //发送场景
570     virtual bool __cdecl SendGameScene(WORD wChiarID, IServerUserItem * pIServerUserItem, BYTE bGameStatus, bool bSendSecret)=NULL;
571     //人工智能游戏动作
572     virtual bool __cdecl OnPerformAIGameAction()=NULL;
573 
574     //事件接口
575 public:
576     //定时器事件
577     virtual bool __cdecl OnTimerMessage(WORD wTimerID, WPARAM wBindParam)=NULL;
578     //游戏消息
579     virtual bool __cdecl OnGameMessage(WORD wSubCmdID, const void * pDataBuffer, WORD wDataSize, IServerUserItem * pIServerUserItem)=NULL;
580     //框架消息
581     virtual bool __cdecl OnFrameMessage(WORD wSubCmdID, const void * pDataBuffer, WORD wDataSize, IServerUserItem * pIServerUserItem)=NULL;
582 };
583 
584 //////////////////////////////////////////////////////////////////////////
585 
586 #ifdef _UNICODE
587     #define VER_ITableUserAction INTERFACE_VERSION(5,2)
588     static const GUID IID_ITableUserAction={0x72c11395,0x1ee9,0x4dc2,0xa8,0x66,0x0e,0x3f,0xfb,0xca,0xbb,0xaf};
589 #else
590     #define VER_ITableUserAction INTERFACE_VERSION(5,2)
591     static const GUID IID_ITableUserAction={0xfaf49c38,0x0d59,0x4ab8,0xb2,0x3b,0x03,0xde,0x56,0x7d,0x00,0xd1};
592 #endif
593 
594 //动作事件
595 interface ITableUserAction : public IUnknownEx
596 {
597     //用户断线
598     virtual bool __cdecl OnActionUserOffLine(WORD wChairID, IServerUserItem * pIServerUserItem)=NULL;
599     //用户重入
600     virtual bool __cdecl OnActionUserReConnect(WORD wChairID, IServerUserItem * pIServerUserItem)=NULL;
601     //用户坐下
602     virtual bool __cdecl OnActionUserSitDown(WORD wChairID, IServerUserItem * pIServerUserItem, bool bLookonUser)=NULL;
603     //用户起来
604     virtual bool __cdecl OnActionUserStandUp(WORD wChairID, IServerUserItem * pIServerUserItem, bool bLookonUser)=NULL;
605     //用户同意
606     virtual bool __cdecl OnActionUserReady(WORD wChairID, IServerUserItem * pIServerUserItem, VOID * pData, WORD wDataSize)=NULL;
607 };
608 
609 //////////////////////////////////////////////////////////////////////////
610 
611 #ifdef _UNICODE
612     #define VER_IAndroidUserItem INTERFACE_VERSION(5,2)
613     static const GUID IID_IAndroidUserItem={0x8eab7240,0xd355,0x4b93,0x9f,0xb3,0x03,0x00,0xac,0xde,0x50,0xfb};
614 #else
615     #define VER_IAndroidUserItem INTERFACE_VERSION(5,2)
616     static const GUID IID_IAndroidUserItem={0xc83ac2b5,0x9e18,0x4909,0xb0,0x7e,0xd5,0x7c,0x56,0x9b,0x16,0x4b};
617 #endif
618 
619 //机器人接口
620 interface IAndroidUserItem : public IUnknownEx
621 {
622     //状态函数
623 public:
624     //获取状态
625     virtual BYTE __cdecl GetGameStatus()=NULL;
626     //设置状态
627     virtual VOID __cdecl SetGameStatus(BYTE cbGameStatus)=NULL;
628 
629     //信息接口
630 public:
631     //获取 I D
632     virtual DWORD __cdecl GetUserID()=NULL;
633     //桌子号码
634     virtual WORD __cdecl GetTableID()=NULL;
635     //椅子号码
636     virtual WORD __cdecl GetChairID()=NULL;
637 
638     //功能接口
639 public:
640     //获取自己
641     virtual IServerUserItem * __cdecl GetMeUserItem()=NULL;
642     //游戏用户
643     virtual IServerUserItem * __cdecl GetTableUserItem(WORD wChariID)=NULL;
644 
645     //网络接口
646 public:
647     //发送函数
648     virtual bool __cdecl SendSocketData(WORD wSubCmdID)=NULL;
649     //发送函数
650     virtual bool __cdecl SendSocketData(WORD wSubCmdID, VOID * pData, WORD wDataSize)=NULL;
651 
652     //功能接口
653 public:
654     //删除时间
655     virtual bool __cdecl KillGameTimer(UINT nTimerID)=NULL;
656     //设置时间
657     virtual bool __cdecl SetGameTimer(UINT nTimerID, UINT nElapse)=NULL;
658     //发送准备
659     virtual bool __cdecl SendUserReady(VOID * pData, WORD wDataSize)=NULL;
660     //发送聊天
661     virtual bool __cdecl SendChatMessage(DWORD dwTargetUserID, LPCTSTR pszChatMessage, COLORREF crFontColor)=NULL;
662 };
663 
664 //////////////////////////////////////////////////////////////////////////
665 
666 #ifdef _UNICODE
667     #define VER_IAndroidUserItemSink INTERFACE_VERSION(5,2)
668     static const GUID IID_IAndroidUserItemSink={0xf87ebc8b,0xb80d,0x4a6d,0x9b,0x7b,0x40,0x2a,0x3e,0xd6,0x30,0x42};
669 #else
670     #define VER_IAndroidUserItemSink INTERFACE_VERSION(5,2)
671     static const GUID IID_IAndroidUserItemSink={0x43ef04c6,0x04e9,0x4603,0x92,0xff,0x97,0xda,0x1f,0x70,0x31,0x62};
672 #endif
673 
674 //机器人接口
675 interface IAndroidUserItemSink : public IUnknownEx
676 {
677     //控制接口
678 public:
679     //初始接口
680     virtual bool __cdecl InitUserItemSink(IUnknownEx * pIUnknownEx)=NULL;
681     //重置接口
682     virtual bool __cdecl RepositUserItemSink()=NULL;
683 
684     //游戏事件
685 public:
686     //时间消息
687     virtual bool __cdecl OnEventTimer(UINT nTimerID)=NULL;
688     //游戏消息
689     virtual bool __cdecl OnEventGameMessage(WORD wSubCmdID, VOID * pData, WORD wDataSize)=NULL;
690     //游戏消息
691     virtual bool __cdecl OnEventFrameMessage(WORD wSubCmdID, VOID * pData, WORD wDataSize)=NULL;
692     //场景消息
693     virtual bool __cdecl OnEventGameScene(BYTE cbGameStatus, bool bLookonOther, VOID * pData, WORD wDataSize)=NULL;
694 
695     //用户事件
696 public:
697     //用户进入
698     virtual VOID __cdecl OnEventUserEnter(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)=NULL;
699     //用户离开
700     virtual VOID __cdecl OnEventUserLeave(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)=NULL;
701     //用户积分
702     virtual VOID __cdecl OnEventUserScore(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)=NULL;
703     //用户状态
704     virtual VOID __cdecl OnEventUserStatus(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)=NULL;
705     //用户段位
706     virtual VOID __cdecl OnEventUserSegment(IAndroidUserItem * pIAndroidUserItem, bool bLookonUser)=NULL;
707 };
708 
709 //////////////////////////////////////////////////////////////////////////
710 
711 #ifdef _UNICODE
712     #define VER_IAndroidUserManager INTERFACE_VERSION(5,2)
713     static const GUID IID_IAndroidUserManager={0xbf347008,0x96d7,0x4ca7,0xb2,0x25,0xe9,0xbe,0x0e,0x04,0x94,0xfd};
714 #else
715     #define VER_IAndroidUserManager INTERFACE_VERSION(5,2)
716     static const GUID IID_IAndroidUserManager={0xe79d8438,0xe020,0x4bf4,0x80,0x5e,0x8b,0x7a,0x10,0xdc,0xd0,0xad};
717 #endif
718 
719 //机器人接口
720 interface IAndroidUserManager : public IUnknownEx
721 {
722     //控制接口
723 public:
724     //停止服务
725     virtual bool __cdecl EndService()=NULL;
726     //启动服务
727     virtual bool __cdecl BeginService()=NULL;
728 
729     //配置接口
730 public:
731     //设置库存
732     virtual bool __cdecl SetAndroidStock(DWORD dwAndroidStock[], WORD wStockCount)=NULL;
733 
734     //管理接口
735 public:
736     //删除机器人
737     virtual bool __cdecl DeleteAndroidUserItem(DWORD dwAndroidID)=NULL;
738     //切换机器人
739     virtual IAndroidUserItem * __cdecl SwitchAndroidUserItem(IServerUserItem * pIServerUserItem)=NULL;
740     //创建机器人
741     virtual IAndroidUserItem * __cdecl CreateAndroidUserItem(DWORD dwUserID, TCHAR szPassword[PASS_LEN])=NULL;
742 
743     //事件接口
744 public:
745     //脉冲事件
746     virtual bool __cdecl OnEventTimerPulse(WORD wTimerID, WPARAM dwBindParameter)=NULL;
747 
748     //网络接口
749 public:
750     //发送数据
751     virtual bool __cdecl SendDataToClient(WORD wMainCmdID, WORD wSubCmdID, VOID * pData, WORD wDataSize)=NULL;
752     //发送数据
753     virtual bool __cdecl SendDataToClient(DWORD dwAndroidID, WORD wMainCmdID, WORD wSubCmdID, VOID * pData, WORD wDataSize)=NULL;
754     //发送数据
755     virtual bool __cdecl SendDataToServer(DWORD dwAndroidID, WORD wMainCmdID, WORD wSubCmdID, VOID * pData, WORD wDataSize)=NULL;
756 };
757 
758 //////////////////////////////////////////////////////////////////////////
759 
760 #ifdef _UNICODE
761     #define VER_IGameServiceFrame INTERFACE_VERSION(5,2)
762     static const GUID IID_IGameServiceFrame={0x1a009277,0x069d,0x42a2,0xb9,0xde,0x5b,0x39,0x29,0x0b,0xf9,0x9c};
763 #else
764     #define VER_IGameServiceFrame INTERFACE_VERSION(5,2)
765     static const GUID IID_IGameServiceFrame={0x4d4395f9,0xb18e,0x4b30,0xad,0xc0,0xfb,0x09,0x02,0xd6,0xf9,0x40};
766 #endif
767 
768 //游戏服务框架
769 interface IGameServiceFrame : public IUnknownEx
770 {
771     //状态接口
772 public:
773     //关闭查询
774     virtual bool __cdecl IsShallClose()=NULL;
775     //私聊查询
776     virtual bool __cdecl IsAllowWisper()=NULL;
777     //聊天查询
778     virtual bool __cdecl IsAllowRoomChat()=NULL;
779     //聊天查询
780     virtual bool __cdecl IsAllowGameChat()=NULL;
781     //进入查询
782     virtual bool __cdecl IsAllowEnterRoom()=NULL;
783     //进入查询
784     virtual bool __cdecl IsAllowEnterGame()=NULL;
785 
786     //状态通知
787 public:
788     //发送状态
789     virtual bool __cdecl SendTableStatus(WORD wTableID)=NULL;
790     //发送分数
791     virtual bool __cdecl SendUserScore(IServerUserItem * pIServerUserItem)=NULL;
792     //发送状态
793     virtual bool __cdecl SendUserStatus(IServerUserItem * pIServerUserItem)=NULL;
794 
795     //网络接口
796 public:
797     //发送数据
798     virtual bool __cdecl SendData(IServerUserItem * pIServerUserItem, WORD wMainCmdID, WORD wSubCmdID)=NULL;
799     //发送数据
800     virtual bool __cdecl SendData(IServerUserItem * pIServerUserItem, WORD wMainCmdID, WORD wSubCmdID, void * pData, WORD wDataSize)=NULL;
801 
802     //定时器接口
803 public:
804     //设置定时器
805     virtual bool __cdecl SetTableTimer(WORD wTableID, WORD wTimerID, DWORD dwElapse, DWORD dwRepeat, WPARAM wBindParam)=NULL; 
806     //删除定时器
807     virtual bool __cdecl KillTableTimer(WORD wTableID, WORD wTimerID)=NULL;
808 
809     //管理接口
810 public:
811     //删除用户
812     virtual bool __cdecl DeleteUserItem(IServerUserItem * pIServerUserItem)=NULL;
813     //记录游戏
814     virtual void __cdecl RecordGameDetails(tagRecordGameDetails* pRecordGame)=NULL;
815     ////记录游戏分数
816     //virtual void __cdecl RecordGameScore(tagRecordGameDetails* pRecordGame)=NULL;
817     //记录用户分数
818     virtual void __cdecl WriteUserScore(IServerUserItem* pIServerUserItem)=NULL;
819     //输出信息
820     virtual void __cdecl ExportInformation(LPCTSTR pszString, enTraceLevel TraceLevel)=NULL;
821 };
822 
823 //////////////////////////////////////////////////////////////////////////
824 
825 #ifdef _UNICODE
826     #define VER_IGameServiceManager INTERFACE_VERSION(5,2)
827     static const GUID IID_IGameServiceManager={0xd5bdced3,0xfecd,0x450b,0xa8,0x63,0xe8,0xef,0x55,0x54,0x6f,0x40};
828 #else
829     #define VER_IGameServiceManager INTERFACE_VERSION(5,2)
830     static const GUID IID_IGameServiceManager={0x27052abc,0x3f1a,0x4369,0x98,0x24,0x8f,0x94,0x1f,0xae,0x98,0x3f};
831 #endif
832 
833 //游戏服务器管理接口
834 interface IGameServiceManager : public IUnknownEx
835 {
836     //参数接口
837 public:
838     //获取属性
839     virtual void __cdecl GetGameServiceAttrib(tagGameServiceAttrib & GameServiceAttrib)=NULL;
840     //修改参数
841     virtual bool __cdecl RectifyServiceOption(tagGameServiceOption * pGameServiceOption)=NULL;
842 
843     //创建接口
844 public:
845     //创建桌子
846     virtual VOID * __cdecl CreateTableFrameSink(REFGUID Guid, DWORD dwQueryVer)=NULL;
847     //创建机器
848     virtual VOID * __cdecl CreateAndroidUserItemSink(REFGUID Guid, DWORD dwQueryVer)=NULL;
849 };
850 
851 //////////////////////////////////////////////////////////////////////////
852 
853 #ifdef _UNICODE
854     #define VER_IGameService INTERFACE_VERSION(5,2)
855     static const GUID IID_IGameService={0xcefa9ee9,0xb11f,0x47f9,0x8b,0xe1,0x92,0x70,0x25,0xfe,0x5d,0x57};
856 #else
857     #define VER_IGameService INTERFACE_VERSION(5,2)
858     static const GUID IID_IGameService={0x93376fd3,0xc55d,0x45d4,0xbd,0x43,0x3d,0x20,0x15,0x72,0x2e,0xb9};
859 #endif
860 
861 //游戏服务接口
862 interface IGameService : public IUnknownEx
863 {
864     //服务状态
865     virtual bool __cdecl IsService()=NULL;
866     //设置事件
867     virtual bool __cdecl SetEventService(IUnknownEx * pIEventService)=NULL;
868     //开始服务
869     virtual bool __cdecl StartService(tagGameServiceParameter * pGameServiceParameter)=NULL;
870     //停止服务
871     virtual bool __cdecl StopService()=NULL;
872 };
873 
874 //////////////////////////////////////////////////////////////////////////
875 
876 //游戏服务组件辅助类
877 class CGameServiceHelper : public CTempldateHelper<IGameService>
878 {
879     //函数定义
880 public:
881     //构造函数
882     CGameServiceHelper(void) : CTempldateHelper<IGameService>(IID_IGameService,
883         VER_IGameService,GAME_SERVICE_DLL_NAME,TEXT("CreateGameService")) { }
884 };
885 
886 //////////////////////////////////////////////////////////////////////////
887 
888 #endif
GameServiceExport.h

头文件GlobalField.h:

bubuko.com,布布扣
  1 #ifndef GLOBAL_FIELD_HEAD_FILE
  2 #define GLOBAL_FIELD_HEAD_FILE
  3 
  4 #include "GlobalDef.h"
  5 
  6 //////////////////////////////////////////////////////////////////////////
  7 
  8 //数据描述头
  9 struct tagDataDescribe
 10 {
 11     WORD                            wDataSize;                        //数据大小
 12     WORD                            wDataDescribe;                    //数据描述
 13 };
 14 
 15 //////////////////////////////////////////////////////////////////////////
 16 
 17 //默认信息
 18 #define DTP_NULL                        0                                //无效数据
 19 
 20 //基础信息
 21 //基础信息
 22 #define DTP_USER_ID                        1                                //用户 I D
 23 #define DTP_GAME_ID                        2                                //用户 I D
 24 #define    DTP_USER_ACCOUNTS                3                                //用户帐号
 25 #define    DTP_USER_NICKNAME                4                                //用户昵称
 26 #define    DTP_USER_PASS                    5                                //用户密码
 27 #define DTP_USER_GENDER                    6                                //用户性别
 28 #define DTP_USER_FACE                    7                                //用户头像
 29 #define DTP_USER_RIGHT                    8                                //用户权限
 30 #define DTP_MASTER_RIGHT                9                                //管理权限
 31 #define    DTP_UNDER_WRITE                    10                                //个性签名
 32 
 33 //状态信息
 34 #define DTP_USER_STATUS                    100                                //用户状态
 35 #define DTP_USER_TABLE                    101                                //游戏桌号
 36 #define DTP_USER_CHAIR                    102                                //椅子号码
 37 #define DTP_USER_PING                    103                                //网络延时
 38 #define DTP_USER_INDEX                    104                                //用户索引
 39 #define DTP_USER_ROUND                    105                                //循环计数
 40 
 41 //积分信息
 42 #define DTP_USER_WIN                    200                                //胜局盘数
 43 #define DTP_USER_LOST                    201                                //输局盘数
 44 #define DTP_USER_DRAW                    202                                //和局盘数
 45 #define DTP_USER_FLEE                    203                                //逃局盘数
 46 #define DTP_WIN_RATE                    204                                //用户胜率
 47 #define DTP_LOST_RATE                    205                                //用户输率
 48 #define DTP_DRAW_RATE                    206                                //用户和率
 49 #define DTP_FLEE_RATE                    207                                //用户逃率
 50 #define DTP_USER_TAX                    208                                //用户税收
 51 #define DTP_USER_GOLD                    209                                //用户金币
 52 #define DTP_USER_SCORE                    210                                //用户分数
 53 #define DTP_USER_PLAY_COUNT                211                                //总局盘数
 54 #define DTP_USER_EXPERIENCE                212                                //用户经验
 55 #define DTP_GAME_LEVEL                    213                                //游戏等级
 56 #define DTP_COMMUNITY_LEVEL                214                                //社区等级
 57 
 58 //扩展信息
 59 #define DTP_USER_GROUP_ID                300                                //社团 I D
 60 #define DTP_USER_GROUP_NAME                301                                //社团名字
 61 #define DTP_USER_NOTE                    302                                //用户备注
 62 #define DTP_USER_DESCRIBE                303                                //用户描述
 63 #define DTP_USER_COMPANION                304                                //用户关系
 64 
 65 //系统信息
 66 #define DTP_COMPUTER_ID                    1000                            //机器序列
 67 #define DTP_STATION_PAGE                1001                            //站点页面
 68 #define DTP_OPTION_BUFFER                1002                            //配置信息
 69 #define DTP_LOCAL_INFO                    1003                            //本机信息
 70 
 71 //////////////////////////////////////////////////////////////////////////
 72 
 73 //数据包辅助类
 74 class CSendPacketHelper
 75 {
 76     //变量定义
 77 protected:
 78     WORD                                m_wDataSize;                    //数据大小
 79     WORD                                m_wBufferSize;                    //缓冲大小
 80     BYTE                                * m_pcbBuffer;                    //缓冲指针
 81 
 82     //函数定义
 83 public:
 84     //构造函数
 85     CSendPacketHelper(void * pcbBuffer, WORD wBufferSize)
 86     {
 87         m_wDataSize=0;
 88         m_wBufferSize=wBufferSize;
 89         m_pcbBuffer=(BYTE *)pcbBuffer;
 90     }
 91     //析构函数
 92     virtual ~CSendPacketHelper() {}
 93 
 94     //功能函数
 95 public:
 96     //清理数据
 97     void CleanData() { m_wDataSize=0; }
 98     //获取大小
 99     WORD GetDataSize() { return m_wDataSize; }
100     //获取缓冲
101     void * GetDataBuffer() { return m_pcbBuffer; }
102     //插入数据
103     bool AddPacket(void * pData, WORD wDataSize, WORD wDataType)
104     {
105         //效验大小
106         ASSERT((wDataSize+sizeof(tagDataDescribe)+m_wDataSize)<=m_wBufferSize);
107         if ((wDataSize+sizeof(tagDataDescribe)+m_wDataSize)>m_wBufferSize) return false;
108 
109         //插入数据
110         ASSERT(m_pcbBuffer!=NULL);
111         tagDataDescribe * pDataDescribe=(tagDataDescribe *)(m_pcbBuffer+m_wDataSize);
112         pDataDescribe->wDataSize=wDataSize;
113         pDataDescribe->wDataDescribe=wDataType;
114 
115         //插入数据
116         if (wDataSize>0)
117         {
118             ASSERT(pData!=NULL);
119             CopyMemory(pDataDescribe+1,pData,wDataSize);
120         }
121 
122         //设置数据
123         m_wDataSize+=sizeof(tagDataDescribe)+wDataSize;
124     
125         return true;
126     }
127 };
128 
129 /////////////////////////////////////////////////////////////////////////////////////////
130 
131 //数据包辅助类
132 class CRecvPacketHelper
133 {
134     //变量定义
135 protected:
136     WORD                                m_wDataPos;                        //数据点
137     WORD                                m_wDataSize;                    //数据大小
138     BYTE                                * m_pcbBuffer;                    //缓冲指针
139 
140     //函数定义
141 public:
142     //构造函数
143     CRecvPacketHelper(LPCVOID pcbBuffer, WORD wDataSize)
144     {
145         m_wDataPos=0;
146         m_wDataSize=wDataSize;
147         m_pcbBuffer=(BYTE *)pcbBuffer;
148     }
149     //析构函数
150     virtual ~CRecvPacketHelper() {}
151 
152     //功能函数
153 public:
154     //获取数据
155     void * GetData(tagDataDescribe & DataDescribe)
156     {
157         //效验数据
158         if (m_wDataPos>=m_wDataSize) 
159         {
160             ASSERT(m_wDataPos==m_wDataSize);
161             DataDescribe.wDataSize=0;
162             DataDescribe.wDataDescribe=DTP_NULL;
163             return NULL;
164         }
165 
166         //获取数据
167         ASSERT((m_wDataPos+sizeof(tagDataDescribe))<=m_wDataSize);
168         CopyMemory(&DataDescribe,m_pcbBuffer+m_wDataPos,sizeof(tagDataDescribe));
169         ASSERT((m_wDataPos+sizeof(tagDataDescribe)+DataDescribe.wDataSize)<=m_wDataSize);
170 
171         //效验数据
172         if ((m_wDataPos+sizeof(tagDataDescribe)+DataDescribe.wDataSize)>m_wDataSize)
173         {
174             DataDescribe.wDataSize=0;
175             DataDescribe.wDataDescribe=DTP_NULL;
176             return NULL;
177         }
178 
179         //设置数据
180         void * pData=NULL;
181         if (DataDescribe.wDataSize>0) pData=m_pcbBuffer+m_wDataPos+sizeof(tagDataDescribe);
182         m_wDataPos+=sizeof(tagDataDescribe)+DataDescribe.wDataSize;
183         return pData;
184     };
185 };
186 
187 //////////////////////////////////////////////////////////////////////////
188 
189 #endif
GlobalField.h

头文件GlobalFrame.h:

bubuko.com,布布扣
  1 #ifndef GLOBAL_FRAME_HEAD_FILE
  2 #define GLOBAL_FRAME_HEAD_FILE
  3 
  4 #pragma once
  5 
  6 #include "GlobalDef.h"
  7 #include "..\..\服务器组件\内核组件\ServerKernel.h"
  8 
  9 //////////////////////////////////////////////////////////////////////////
 10 //宏定义
 11 
 12 //游戏状态
 13 #define GS_FREE                            0                                //空闲状态
 14 #define GS_PLAYING                        100                                //游戏状态
 15 
 16 //////////////////////////////////////////////////////////////////////////
 17 //IPC 网络事件
 18 
 19 #define IPC_MAIN_SOCKET                    1                                //网络消息
 20 
 21 #define IPC_SUB_SOCKET_SEND                1                                //网络发送
 22 #define IPC_SUB_SOCKET_RECV                2                                //网络接收
 23 
 24 //IPC 网络包结构
 25 struct IPC_SocketPackage
 26 {
 27     CMD_Command                            Command;                        //命令信息
 28     BYTE                                cbBuffer[SOCKET_PACKAGE];        //数据缓冲
 29 };
 30 
 31 //////////////////////////////////////////////////////////////////////////
 32 //IPC 配置信息
 33 
 34 #define IPC_MAIN_CONFIG                    2                                //配置信息
 35 
 36 #define IPC_SUB_SERVER_INFO                1                                //房间信息
 37 #define IPC_SUB_COLUMN_INFO                2                                //列表信息
 38 
 39 //游戏信息
 40 struct IPC_GF_ServerInfo
 41 {
 42     DWORD                                dwUserID;                        //用户 I D
 43     WORD                                wTableID;                        //桌子号码
 44     WORD                                wChairID;                        //椅子号码
 45     WORD                                wKindID;                        //类型标识
 46     WORD                                wServerID;                        //房间标识
 47     WORD                                wGameGenre;                        //游戏类型
 48     WORD                                wChairCount;                    //椅子数目
 49     BOOL                                bHideUserInfo;                    //隐藏信息
 50     DWORD                                dwVideoAddr;                    //视频地址
 51     TCHAR                                szKindName[KIND_LEN];            //类型名字
 52     TCHAR                                szServerName[MODULE_LEN];        //房间名称
 53     tagOptionBuffer                        OptionBuffer;                    //配置信息
 54 };
 55 
 56 //////////////////////////////////////////////////////////////////////////
 57 //IPC 用户信息
 58 
 59 #define IPC_MAIN_USER                    3                                //用户信息
 60 
 61 #define IPC_SUB_USER_COME                1                                //用户信息
 62 #define IPC_SUB_USER_STATUS                2                                //用户状态
 63 #define IPC_SUB_USER_SCORE                3                                //用户积分
 64 #define IPC_SUB_GAME_START                4                                //游戏开始
 65 #define IPC_SUB_GAME_FINISH                5                                //游戏结束
 66 
 67 //用户状态
 68 struct IPC_UserStatus
 69 {
 70     DWORD                                dwUserID;                        //用户 I D
 71     WORD                                wNetDelay;                        //网络延时
 72     BYTE                                cbUserStatus;                    //用户状态
 73 };
 74 
 75 //用户分数
 76 struct IPC_UserScore
 77 {
 78     DWORD                                dwUserID;                        //用户 I D
 79     tagUserScore                        UserScore;                        //用户积分
 80 };
 81 
 82 //////////////////////////////////////////////////////////////////////////
 83 //IPC 控制信息
 84 
 85 #define IPC_MAIN_CONCTROL                4                                //控制信息
 86 
 87 #define IPC_SUB_START_FINISH            1                                //启动完成
 88 #define IPC_SUB_CLOSE_FRAME                2                                //关闭框架
 89 #define IPC_SUB_JOIN_IN_GAME            3                                //加入游戏
 90 #define IPC_SUB_CONTINUE_GAME           4                               //继续游戏
 91 #define IPC_SUB_RETURN_PLAZA            5                               //返回大厅
 92 #define IPC_SUB_APPLY_CLOSE                6                                //关闭框架
 93 //加入游戏
 94 struct IPC_JoinInGame
 95 {
 96     WORD                                wTableID;                        //桌子号码
 97     WORD                                wChairID;                        //椅子号码
 98 };
 99 
100 //////////////////////////////////////////////////////////////////////////
101 //IPC 启动消息
102 #define IPC_MAIN_KONGZHI                5                                //控制信息
103 
104 #define IPC_SUB_START                   1                               //启动服务
105 #define IPC_SUB_STOP                    2                               //停止服务
106 #define IPC_SUB_KILL                    3                               //关闭服务
107 
108 //IPC 返回消息
109 #define IPC_MAIN_BACK                     6                                //返回信息
110 
111 #define IPC_SUB_BACK_HWND               1                               //返回成功加载的房间信息 
112 #define IPC_SUB_BACK_INFO               2                               //返回启动的游戏房间服务信息
113 #define IPC_SUB_BACK_ERRORINFO          3                               //返回文字信息
114 #define IPC_SUB_BACK_STOP               4                               //返回停止的游戏房间服务信息
115 
116 #define MAXLENGTH 200
117 
118 //返回句柄
119 struct IPC_BackInfo
120 {
121     HWND  hWnd;                                                        //接收句柄
122     int   wServerId;                                                   //wServerId
123     TCHAR RoomPathName[MAXLENGTH];                                     //游戏房间文件路径
124 };
125 
126 //返回文字信息
127 struct IPC_BackErrorInfo
128 {
129     TCHAR    szStr[MAXLENGTH];                                          //描述
130     enTraceLevel TraceLevel;                                          //类型
131 };
132 
133 //返回文字信息
134 struct IPC_BackErrorInfo_X
135 {
136     TCHAR    szStr[MAXLENGTH];                                          //描述
137     enTraceLevel TraceLevel;                                          //类型
138     HWND  hWnd;                                                       //接收句柄
139 };
140 
141 //进入房间扣金币
142 struct CMD_GF_GetOutMoney
143 {
144     DWORD                                dwUserID;                        //用户ID
145     LONG                                lScore;                            //用户分数
146 };
147 
148 //////////////////////////////////////////////////////////////////////////
149 //网络命令码
150 
151 #define MDM_GF_GAME                        100                                //游戏消息
152 #define MDM_GF_FRAME                    101                                //框架消息
153 
154 #define SUB_GF_INFO                        1                                //游戏信息
155 #define SUB_GF_USER_READY                2                                //用户同意
156 #define SUB_GF_LOOKON_CONTROL            3                                //旁观控制
157 #define SUB_GF_KICK_TABLE_USER            4                                //踢走用户
158 
159 #define SUB_GF_OPTION                    100                                //游戏配置
160 #define SUB_GF_SCENE                    101                                //场景信息
161 
162 #define SUB_GF_USER_CHAT                200                                //用户聊天
163 
164 #define SUB_GF_MESSAGE                    300                                //系统消息
165 
166 //版本信息
167 struct CMD_GF_Info
168 {
169     BYTE                                bAllowLookon;                    //旁观标志
170 };
171 
172 //游戏配置
173 struct CMD_GF_Option
174 {
175     BYTE                                bGameStatus;                    //游戏状态
176     BYTE                                bAllowLookon;                    //允许旁观
177 };
178 
179 //旁观控制
180 struct CMD_GF_LookonControl
181 {
182     DWORD                                dwUserID;                        //用户标识
183     BYTE                                bAllowLookon;                    //允许旁观
184 };
185 
186 //踢走用户
187 struct CMD_GF_KickTableUser
188 {
189     DWORD                                dwUserID;                        //用户 I D
190 };
191 
192 //聊天结构
193 struct CMD_GF_UserChat
194 {
195     WORD                                wChatLength;                    //信息长度
196     COLORREF                            crFontColor;                    //信息颜色
197     DWORD                                dwSendUserID;                    //发送用户
198     DWORD                                dwTargetUserID;                    //目标用户
199     TCHAR                                szChatMessage[MAX_CHAT_LEN];    //聊天信息
200 };
201 
202 //消息类型
203 #define SMT_INFO                        0x0001                            //信息消息
204 #define SMT_EJECT                        0x0002                            //弹出消息
205 #define SMT_GLOBAL                        0x0004                            //全局消息
206 #define SMT_CLOSE_GAME                    0x1000                            //关闭游戏
207 
208 //消息数据包
209 struct CMD_GF_Message
210 {
211     WORD                            wMessageType;                        //消息类型
212     WORD                            wMessageLength;                        //消息长度
213     TCHAR                            szContent[1024];                    //消息内容
214 };
215 
216 //////////////////////////////////////////////////////////////////////////
217 
218 //共享内存定义
219 struct tagShareMemory
220 {
221     WORD                                wDataSize;                        //数据大小
222     HWND                                hWndGameFrame;                    //框架句柄
223     HWND                                hWndGamePlaza;                    //广场句柄
224     HWND                                hWndGameServer;                    //房间句柄
225 };
226 
227 //////////////////////////////////////////////////////////////////////////
228 
229 #endif
GlobalFrame.h

头文件GlobalRight.h:

bubuko.com,布布扣
 1 #ifndef GLOBAL_RIGHT_HEAD_FILE
 2 #define GLOBAL_RIGHT_HEAD_FILE
 3 
 4 //////////////////////////////////////////////////////////////////////////
 5 
 6 //玩家权限定义
 7 #define UR_CANNOT_PLAY                    0x00000001L                //不能进行游戏
 8 #define UR_CANNOT_LOOKON                0x00000002L                //不能旁观游戏
 9 #define UR_CANNOT_WISPER                0x00000004L                //不能发送私聊
10 #define UR_CANNOT_ROOM_CHAT                0x00000008L                //不能大厅聊天
11 #define UR_CANNOT_GAME_CHAT                0x00000010L                //不能游戏聊天
12 
13 //标志权限定义
14 #define UR_MATCH_USER                    0x10000000L                //比赛用户标志
15 #define UR_GM_USER                        0x20000000L                //游戏管理员标志
16 
17 //管理权限定义
18 #define UR_CAN_LIMIT_PLAY                0x00000001L                //允许禁止游戏
19 #define UR_CAN_LIMIT_LOOKON                0x00000002L                //允许禁止旁观
20 #define UR_CAN_LIMIT_WISPER                0x00000004L                //允许禁止私聊
21 #define UR_CAN_LIMIT_ROOM_CHAT            0x00000008L                //允许禁止聊天
22 #define UR_CAN_LIMIT_GAME_CHAT            0x00000010L                //允许禁止聊天
23 #define UR_CAN_CUT_USER                    0x00000020L                //允许踢出用户
24 #define UR_CAN_FORBID_ACCOUNTS            0x00000040L                //允许封锁帐号
25 #define UR_CAN_CONFINE_IP                0x00000080L                //允许禁止地址
26 #define UR_CAN_SEE_USER_IP                0x00000100L                //允许查看地址
27 #define UR_CAN_SEND_WARNING                0x00000200L                //允许发送警告
28 #define UR_CAN_ISSUE_MESSAGE            0x00000400L                //允许发布消息
29 #define UR_CAN_BIND_GAME                0x00000800L                //允许游戏绑定
30 #define UR_CAN_BIND_GLOBAL                0x00001000L                //允许全局绑定
31 #define UR_CAN_SERVER_OPTION            0x00002000L                //允许配置房间
32 
33 //////////////////////////////////////////////////////////////////////////
34 
35 //权限辅助类
36 class CUserRight
37 {
38     //玩家权限
39 public:
40     //游戏权限
41     static bool CanPlay(LONG lUserRight) { return (lUserRight&UR_CANNOT_PLAY)==0; }
42     //旁观权限
43     static bool CanLookon(LONG lUserRight) { return (lUserRight&UR_CANNOT_LOOKON)==0; }
44     //私聊权限
45     static bool CanWisper(LONG lUserRight) { return (lUserRight&UR_CANNOT_WISPER)==0; }
46     //大厅聊天
47     static bool CanRoomChat(LONG lUserRight) { return (lUserRight&UR_CANNOT_ROOM_CHAT)==0; }
48     //游戏聊天
49     static bool CanGameChat(LONG lUserRight) { return (lUserRight&UR_CANNOT_GAME_CHAT)==0; }
50 
51     //用户标识
52 public:
53     //比赛标识
54     static bool IsMatchUser(LONG lUserRight) { return (lUserRight&UR_MATCH_USER)!=0; }
55     //GM标识
56     static bool IsGMUser(LONG lUserRight) { return (lUserRight&UR_GM_USER)!=0; }
57 
58     //管理权限
59 public:
60     //禁止游戏
61     static bool CanLimitPlay(LONG lMasterRight) { return ((lMasterRight&UR_CAN_LIMIT_PLAY)!=0); }
62     //禁止旁观
63     static bool CanLimitLookon(LONG lMasterRight) { return ((lMasterRight&UR_CAN_LIMIT_LOOKON)!=0); }
64     //禁止私聊
65     static bool CanLimitWisper(LONG lMasterRight) { return ((lMasterRight&UR_CAN_LIMIT_WISPER)!=0); }
66     //禁止聊天
67     static bool CanLimitRoomChat(LONG lMasterRight) { return ((lMasterRight&UR_CAN_LIMIT_ROOM_CHAT)!=0); }
68     //禁止聊天
69     static bool CanLimitGameChat(LONG lMasterRight) { return ((lMasterRight&UR_CAN_LIMIT_GAME_CHAT)!=0); }
70     //踢出用户
71     static bool CanCutUser(LONG lMasterRight) { return ((lMasterRight&UR_CAN_CUT_USER)!=0); }
72     //封锁帐号
73     static bool CanForbidAccounts(LONG lMasterRight) { return ((lMasterRight&UR_CAN_FORBID_ACCOUNTS)!=0); }
74     //禁止地址
75     static bool CanConfineIP(LONG lMasterRight) { return ((lMasterRight&UR_CAN_CONFINE_IP)!=0); }
76     //查看地址
77     static bool CanSeeUserIP(LONG lMasterRight) { return ((lMasterRight&UR_CAN_SEE_USER_IP)!=0); }
78     //发布消息
79     static bool CanIssueMessage(LONG lMasterRight) { return ((lMasterRight&UR_CAN_ISSUE_MESSAGE)!=0); }
80     //发送警告
81     static bool CanSendWarning(LONG lMasterRight) { return ((lMasterRight&UR_CAN_SEND_WARNING)!=0); }
82     //游戏绑定
83     static bool CanBindGame(LONG lMasterRight) { return ((lMasterRight&UR_CAN_BIND_GAME)!=0); }
84     //全局绑定
85     static bool CanBindGlobal(LONG lMasterRight) { return ((lMasterRight&UR_CAN_BIND_GLOBAL)!=0); }
86     //配置房间
87     static bool CanServerOption(LONG lMasterRight) { return ((lMasterRight&UR_CAN_SERVER_OPTION)!=0); }
88 };
89 
90 //////////////////////////////////////////////////////////////////////////
91 
92 #endif
GlobalRight.h

头文件GlobalService.h:

bubuko.com,布布扣
  1 #ifndef GLOBAL_SERVICE_HEAD_FILE
  2 #define GLOBAL_SERVICE_HEAD_FILE
  3 
  4 #pragma once
  5 
  6 //////////////////////////////////////////////////////////////////////////
  7 
  8 //数据库名字
  9 const TCHAR szGameUserDB[]=TEXT("QPGameUserDB");                        //用户数据库
 10 const TCHAR    szGameDB[]=TEXT("QPGameScoreDB");                                //财富数据库
 11 const TCHAR szServerInfoDB[]=TEXT("ServerInfoDB");                    //房间数据库
 12 
 13 //////////////////////////////////////////////////////////////////////////
 14 
 15 //数据库信息
 16 struct tagDataBaseInfo
 17 {
 18     WORD                            wDataBasePort;                        //数据库端口
 19     DWORD                            dwDataBaseAddr;                        //数据库地址
 20     TCHAR                            szDataBaseUser[32];                    //数据库用户
 21     TCHAR                            szDataBasePass[32];                    //数据库密码
 22     TCHAR                            szDataBaseName[32];                    //数据库名字
 23 };
 24 
 25 //////////////////////////////////////////////////////////////////////////
 26 
 27 //游戏服务属性
 28 struct tagGameServiceAttrib
 29 {
 30     WORD                            wKindID;                            //名称号码
 31     WORD                            wChairCount;                        //椅子数目
 32     BYTE                            cbJoinInGame;                        //游戏加入
 33     TCHAR                            szDataBaseName[32];                    //游戏库名
 34     TCHAR                            szDescription[128];                    //模块描述
 35     TCHAR                            szKindName[KIND_LEN];                //类型名字
 36     TCHAR                            szServerModuleName[MODULE_LEN];        //模块名字
 37     TCHAR                            szClientModuleName[MODULE_LEN];        //模块名字
 38 };
 39 
 40 //游戏服务配置
 41 struct tagGameServiceOption
 42 {
 43     //房间属性
 44     TCHAR                            szGameRoomName[MODULE_LEN];            //房间名称
 45     TCHAR                            szGameRoomPassword[PASSWORD_LEN];    //房间密码
 46     TCHAR                            szStartTime[12];                    //开始时间
 47     TCHAR                            szEndTime[12];                        //结束时间
 48     DOUBLE                            dMinRevenue;                        //最低税收
 49     DOUBLE                            dCellScore;                            //单位积分
 50     DOUBLE                            lLessScore;                            //最低积分
 51     DOUBLE                          lHighScore;                            //最高积分
 52     DOUBLE                            lGuoDiScore;                        //锅底
 53     DOUBLE                            dReductScore;                        //进房扣金币
 54     DWORD                            dwServerAddr;                        //房间地址
 55     DWORD                            dwVideoServer;                        //视频地址
 56     DWORD                           dwNumberBase;                       //房间人数基数
 57     LONG                            lRestrictScore;                        //限制积分
 58     LONG                            lMatchDraw;                            //比赛局数
 59     WORD                            wKindID;                            //类型标识
 60     WORD                            wServerID;                            //房间号码
 61     WORD                            wStationID;                            //站点号码
 62     WORD                            wTableCount;                        //桌子数目
 63     WORD                            wServerPort;                        //房间端口
 64     WORD                            wServerType;                        //房间类型
 65     WORD                            wMaxConnect;                        //最大连接
 66     WORD                            wShowXiaoShuNum;                    //保留小数位数
 67     WORD                            wBeAhead;                            //赢钱比例
 68     BOOL                            bHideUserInfo;                        //隐藏信息
 69     BOOL                            bFZB;                                //防作弊
 70     BOOL                            bAddCellScore;                        //房间加底
 71     BYTE                            cbGameMode;                            //游戏模式
 72     BYTE                            cbRevenue;                            //游戏税收
 73     BYTE                            cbControlStart;                        //控制开始
 74     BYTE                            cbDistributeMode;                    //分配模式
 75 };
 76 
 77 //房间配置信息
 78 struct tagRoomInfo
 79 {
 80     TCHAR                            szGameRoomName[MODULE_LEN];            //房间名称
 81     TCHAR                            szProcessName[MODULE_LEN];            //游戏进程名称
 82     TCHAR                            szDataBaseName[MODULE_LEN];            //数据库名称
 83     TCHAR                            szGameRoomPassword[PASSWORD_LEN];    //房间密码
 84     TCHAR                            szStartTime[12];                    //开始时间
 85     TCHAR                            szEndTime[12];                        //结束时间
 86     DOUBLE                            dCellScore;                            //单元积分
 87     DOUBLE                            dMinRevenue;                        //最低税收
 88     DOUBLE                            lGuoDiScore;                        //房间锅底
 89     DOUBLE                            dReductScore;                        //进房扣金币
 90     DOUBLE                            lLessScore;                            //最低积分
 91     DWORD                           dwNumberBase;                       //人数基数
 92     DWORD                            dwServerAddr;                        //服务地址
 93     DWORD                            dwDataBaseAddr;                        //数据库地址
 94     DWORD                            dwVideoServerAddr;                    //视频地址
 95     WORD                            wServerID;                            //房间标识
 96     WORD                            wKindID;                            //类型标识
 97     WORD                            wTableCount;                        //桌子数目
 98     WORD                            wServerType;                        //游戏类型
 99     WORD                            wMaxConnect;                        //房间人数
100     WORD                            wServerPort;                        //服务端口
101     BYTE                            cbRevenue;                            //游戏税收
102     BYTE                            cbAddCellScore;                        //房间加底
103     BYTE                            cbFZB;                                //防作弊
104     BYTE                            cbGameMode;                            //游戏模式
105     BYTE                            cbHideUserInfo;                        //隐藏信息
106     BYTE                            cbAI;                                //机器人
107     BYTE                            cbAbnormity;                        //异常
108 };
109 //////////////////////////////////////////////////////////////////////////
110 
111 #endif
GlobalService.h

头文件CMD_Game.h:

bubuko.com,布布扣
  1 #ifndef CMD_GAME_HEAD_FILE
  2 #define CMD_GAME_HEAD_FILE
  3 
  4 //////////////////////////////////////////////////////////////////////////
  5 //强退托管宏定义 如果不托管就取消宏定义
  6 #define FORCE_EXIT_TRUSTEE
  7 //////////////////////////////////////////////////////////////////////////
  8 
  9 //登录数据包定义
 10 
 11 #define MDM_GR_LOGON                1                                    //房间登录
 12 
 13 #define SUB_GR_LOGON_ACCOUNTS        1                                    //帐户登录
 14 #define SUB_GR_LOGON_USERID            2                                    //I D 登录
 15 
 16 #define SUB_GR_LOGON_SUCCESS        100                                    //登录成功
 17 #define SUB_GR_LOGON_ERROR            101                                    //登录失败
 18 #define SUB_GR_LOGON_FINISH            102                                    //登录完成
 19 
 20 //房间帐号登录
 21 struct CMD_GR_LogonByAccounts
 22 {
 23     DWORD                            dwPlazaVersion;                        //广场版本
 24     DWORD                            dwProcessVersion;                    //进程版本
 25     TCHAR                            szAccounts[NAME_LEN];                //登录帐号
 26     TCHAR                            szPassWord[PASS_LEN];                //登录密码
 27 };
 28 
 29 //房间 ID 登录
 30 struct CMD_GR_LogonByUserID
 31 {
 32     DWORD                            dwPlazaVersion;                        //广场版本
 33     DWORD                            dwProcessVersion;                    //进程版本
 34     DWORD                            dwUserID;                            //用户 I D
 35     TCHAR                            szPassWord[PASS_LEN];                //登录密码
 36 };
 37 
 38 //登录成功消息
 39 struct CMD_GR_LogonSuccess
 40 {
 41     DWORD                            dwUserID;                            //用户 I D
 42 };
 43 
 44 //登录失败
 45 struct CMD_GR_LogonError
 46 {
 47     LONG                            lErrorCode;                            //错误代码
 48     TCHAR                            szErrorDescribe[128];                //错误消息
 49 };
 50 
 51 //////////////////////////////////////////////////////////////////////////
 52 //用户数据包定义
 53 
 54 #define MDM_GR_USER                    2                                    //用户信息
 55 
 56 #define SUB_GR_USER_SIT_REQ            1                                    //坐下请求
 57 #define SUB_GR_USER_LOOKON_REQ        2                                    //旁观请求
 58 #define SUB_GR_USER_STANDUP_REQ        3                                    //起立请求
 59 #define SUB_GR_USER_LEFT_GAME_REQ    4                                    //离开游戏
 60 
 61 #define SUB_GR_USER_COME            100                                    //用户进入
 62 #define SUB_GR_USER_STATUS            101                                    //用户状态
 63 #define SUB_GR_USER_SCORE            102                                    //用户分数
 64 #define SUB_GR_SIT_FAILED            103                                    //坐下失败
 65 #define SUB_GR_AUTO_SIT             104                                    //捷足先登
 66 
 67 #define SUB_GR_USER_CHAT            200                                    //聊天消息
 68 #define SUB_GR_USER_WISPER            201                                    //私语消息
 69 #define SUB_GR_USER_RULE            202                                    //用户规则
 70 
 71 #define SUB_GR_USER_INVITE            300                                    //邀请消息
 72 #define SUB_GR_USER_INVITE_REQ        301                                    //邀请请求
 73 
 74 //用户状态
 75 struct CMD_GR_UserStatus
 76 {
 77     DWORD                            dwUserID;                            //数据库 ID
 78     WORD                            wTableID;                            //桌子位置
 79     WORD                            wChairID;                            //椅子位置
 80     BYTE                            cbUserStatus;                        //用户状态
 81 };
 82 
 83 //用户分数
 84 struct CMD_GR_UserScore
 85 {
 86     DWORD                            dwUserID;                            //用户 I D
 87     tagUserScore                    UserScore;                            //积分信息
 88 };
 89 
 90 //进入房间扣金币
 91 struct CMD_GR_GetOutMoney
 92 {
 93     DWORD                            dwUserID;                            //数据库 ID
 94     LONG                            lScore;                                //用户分数
 95 };
 96 
 97 //请求坐下
 98 struct CMD_GR_UserSitReq
 99 {
100     WORD                            wTableID;                            //桌子位置
101     WORD                            wChairID;                            //椅子位置
102     BYTE                            cbPassLen;                            //密码长度
103     TCHAR                            szTablePass[PASS_LEN];                //桌子密码
104 };
105 
106 //邀请用户 
107 struct CMD_GR_UserInviteReq
108 {
109     WORD                            wTableID;                            //桌子号码
110     DWORD                            dwUserID;                            //用户 I D
111 };
112 
113 //坐下失败
114 struct CMD_GR_SitFailed
115 {
116     TCHAR                            szFailedDescribe[256];                //错误描述
117 };
118 
119 //聊天结构 
120 struct CMD_GR_UserChat
121 {
122     WORD                            wChatLength;                        //信息长度
123     COLORREF                        crFontColor;                        //信息颜色
124     DWORD                            dwSendUserID;                        //发送用户
125     DWORD                            dwTargetUserID;                        //目标用户
126     TCHAR                            szChatMessage[MAX_CHAT_LEN];        //聊天信息
127 };
128 
129 //私语结构 
130 struct CMD_GR_Wisper
131 {
132     WORD                            wChatLength;                        //信息长度
133     COLORREF                        crFontColor;                        //信息颜色
134     DWORD                            dwSendUserID;                        //发送用户
135     DWORD                            dwTargetUserID;                        //目标用户
136     TCHAR                            szChatMessage[MAX_CHAT_LEN];        //聊天信息
137 };
138 
139 //用户规则
140 struct CMD_GR_UserRule
141 {
142     bool                            bPassword;                            //设置密码
143     bool                            bLimitWin;                            //限制胜率
144     bool                            bLimitFlee;                            //限制断线
145     bool                            bLimitScore;                        //限制分数
146     bool                            bCheckSameIP;                        //效验地址
147     WORD                            wWinRate;                            //限制胜率
148     WORD                            wFleeRate;                            //限制逃跑
149     LONG                            lMaxScore;                            //最高分数 
150     LONG                            lLessScore;                            //最低分数
151     TCHAR                            szPassword[PASS_LEN];                //桌子密码
152 };
153 
154 //邀请用户 
155 struct CMD_GR_UserInvite
156 {
157     WORD                            wTableID;                            //桌子号码
158     DWORD                            dwUserID;                            //用户 I D
159 };
160 
161 //////////////////////////////////////////////////////////////////////////
162 //配置信息数据包
163 
164 #define MDM_GR_INFO                    3                                    //配置信息
165 
166 #define SUB_GR_SERVER_INFO            100                                    //房间配置
167 #define SUB_GR_ORDER_INFO            101                                    //等级配置
168 #define SUB_GR_MEMBER_INFO            102                                    //会员配置
169 #define SUB_GR_COLUMN_INFO            103                                    //列表配置
170 #define SUB_GR_CONFIG_FINISH        104                                    //配置完成
171 
172 //游戏房间信息
173 struct CMD_GR_ServerInfo
174 {
175     //房间属性
176     WORD                            wKindID;                            //类型 I D
177     WORD                            wTableCount;                        //桌子数目
178     WORD                            wChairCount;                        //椅子数目
179     DWORD                            dwVideoAddr;                        //视频地址
180 
181     //扩展配置
182     WORD                            wGameGenre;                            //游戏类型
183     BOOL                            bHideUserInfo;                        //隐藏信息
184     BYTE                            cbDistributeMode;                    //分配模式
185     int    m_isFZBRoom;//是否防作弊房间 0 =no, 1=yes
186 
187     BOOL                            bAddCellScore;                        //是否加底
188 };
189 
190 //分数描述信息
191 struct CMD_GR_ScoreInfo
192 {
193     WORD                            wDescribeCount;                        //描述数目
194     WORD                            wDataDescribe[16];                    //数据标志
195 };
196 
197 //等级描述结构
198 struct tagOrderItem
199 {
200     LONG                            lScore;                                //等级积分
201     WORD                            wOrderDescribe[16];                    //等级描述
202 };
203 
204 //等级描述信息
205 struct CMD_GR_OrderInfo
206 {
207     WORD                            wOrderCount;                        //等级数目
208     tagOrderItem                    OrderItem[128];                        //等级描述
209 };
210 
211 //列表项描述结构
212 struct tagColumnItem
213 {
214     WORD                            wColumnWidth;                        //列表宽度
215     WORD                            wDataDescribe;                        //字段类型
216     TCHAR                            szColumnName[16];                    //列表名字
217 };
218 
219 //列表描述信息
220 struct CMD_GR_ColumnInfo
221 {
222     WORD                            wColumnCount;                        //列表数目
223     tagColumnItem                    ColumnItem[32];                        //列表描述
224 };
225 
226 //////////////////////////////////////////////////////////////////////////
227 //房间状态数据包
228 
229 #define MDM_GR_STATUS                4                                    //状态信息
230 
231 #define SUB_GR_TABLE_INFO            100                                    //桌子信息
232 #define SUB_GR_TABLE_STATUS            101                                    //桌子状态
233 
234 //桌子状态结构
235 struct tagTableStatus
236 {
237     BYTE                            bTableLock;                            //锁定状态
238     BYTE                            bPlayStatus;                        //游戏状态
239 };
240 
241 //桌子状态数组
242 struct CMD_GR_TableInfo
243 {
244     WORD                            wTableCount;                        //桌子数目
245     tagTableStatus                    TableStatus[512];                    //状态数组
246 };
247 
248 //桌子状态信息
249 struct CMD_GR_TableStatus
250 {
251     WORD                            wTableID;                            //桌子号码
252     BYTE                            bPlayStatus;                        //游戏状态
253 };
254 
255 //////////////////////////////////////////////////////////////////////////
256 //管理数据包
257 
258 #define MDM_GR_MANAGER                5                                    //管理命令
259 
260 #define SUB_GR_SEND_WARNING            1                                    //发送警告
261 #define SUB_GR_SEND_MESSAGE            2                                    //发送消息
262 #define SUB_GR_LOOK_USER_IP            3                                    //查看地址
263 #define SUB_GR_KILL_USER            4                                    //踢出用户
264 #define SUB_GR_LIMIT_ACCOUNS        5                                    //禁用帐户
265 #define SUB_GR_SET_USER_RIGHT        6                                    //权限设置
266 #define SUB_GR_OPTION_SERVER        7                                    //房间设置
267 
268 //发送警告
269 struct CMD_GR_SendWarning
270 {
271     WORD                            wChatLength;                        //信息长度
272     DWORD                            dwTargetUserID;                        //目标用户
273     TCHAR                            szWarningMessage[MAX_CHAT_LEN];        //警告消息
274 };
275 
276 //系统消息
277 struct CMD_GR_SendMessage
278 {
279     BYTE                            cbGame;                                //游戏消息
280     BYTE                            cbRoom;                                //游戏消息
281     WORD                            wChatLength;                        //信息长度
282     TCHAR                            szSystemMessage[MAX_CHAT_LEN];        //系统消息
283 };
284 
285 //查看地址
286 struct CMD_GR_LookUserIP
287 {
288     DWORD                            dwTargetUserID;                        //目标用户
289 };
290 
291 //踢出用户
292 struct CMD_GR_KillUser
293 {
294     DWORD                            dwTargetUserID;                        //目标用户
295 };
296 
297 //禁用帐户
298 struct CMD_GR_LimitAccounts
299 {
300     DWORD                            dwTargetUserID;                        //目标用户
301 };
302 
303 //权限设置
304 struct CMD_GR_SetUserRight
305 {
306     //目标用户
307     DWORD                            dwTargetUserID;                        //目标用户
308 
309     //绑定变量
310     BYTE                            cbGameRight;                        //帐号权限
311     BYTE                            cbAccountsRight;                    //帐号权限
312 
313     //权限变化
314     BYTE                            cbLimitRoomChat;                    //大厅聊天
315     BYTE                            cbLimitGameChat;                    //游戏聊天
316     BYTE                            cbLimitPlayGame;                    //游戏权限
317     BYTE                            cbLimitSendWisper;                    //发送消息
318     BYTE                            cbLimitLookonGame;                    //旁观权限
319 };
320 
321 //设置标志
322 #define OSF_ROOM_CHAT                1                                    //大厅聊天
323 #define OSF_GAME_CHAT                2                                    //游戏聊天
324 #define OSF_ROOM_WISPER                3                                    //大厅私聊
325 #define OSF_ENTER_GAME                4                                    //进入游戏
326 #define OSF_ENTER_ROOM                5                                    //进入房间
327 #define OSF_SHALL_CLOSE                6                                    //即将关闭
328 
329 //房间设置
330 struct CMD_GR_OptionServer
331 {
332     BYTE                            cbOptionFlags;                        //设置标志
333     BYTE                            cbOptionValue;                        //设置标志
334 };
335 
336 //////////////////////////////////////////////////////////////////////////
337 //系统数据包
338 
339 #define MDM_GR_SYSTEM                10                                    //系统信息
340 
341 #define SUB_GR_MESSAGE                100                                    //系统消息
342 
343 //消息类型
344 #define SMT_INFO                    0x0001                                //信息消息
345 #define SMT_EJECT                    0x0002                                //弹出消息
346 #define SMT_GLOBAL                    0x0004                                //全局消息
347 #define SMT_CLOSE_ROOM                0x1000                                //关闭房间
348 #define SMT_INTERMIT_LINE            0x4000                                //中断连接
349 
350 //消息数据包
351 struct CMD_GR_Message
352 {
353     WORD                            wMessageType;                        //消息类型
354     WORD                            wMessageLength;                        //消息长度
355     TCHAR                            szContent[1024];                    //消息内容
356 };
357 
358 //////////////////////////////////////////////////////////////////////////
359 //房间数据包
360 
361 #define MDM_GR_SERVER_INFO            11                                    //房间信息
362 
363 #define SUB_GR_ONLINE_COUNT_INFO    100                                    //在线信息
364 
365 //人数信息
366 struct tagOnLineCountInfo
367 {
368     WORD                            wKindID;                            //类型标识
369     DWORD                            dwOnLineCount;                        //在线人数
370 };
371 
372 //////////////////////////////////////////////////////////////////////////
373 
374 #endif
CMD_Game.h

头文件CMD_Video.h:

bubuko.com,布布扣
 1 #ifndef CMD_VIDEO_HEAD_FILE
 2 #define CMD_VIDEO_HEAD_FILE
 3 
 4 //////////////////////////////////////////////////////////////////////////
 5 
 6 #define MDM_GF_VIDEO                200                                    //视频通道
 7 
 8 #define SUB_GF_C_VIDEO_CONFIG        1                                    //视频配置
 9 
10 #define SUB_GF_S_VIDEO_CONFIG        100                                    //视频配置
11 
12 //////////////////////////////////////////////////////////////////////////
13 
14 //视频配置
15 struct CMD_C_VideoConfig
16 {
17     //连接信息
18     WORD                            wNatPort;                            //网络端口
19     WORD                            wLocalPort;                            //网络端口
20     DWORD                            dwNatAddr;                            //网络地址
21     DWORD                            dwLocalAddr;                        //本地地址
22 
23     //用户标识
24     DWORD                            dwRemoteUserID;                        //远程用户
25 };
26 
27 //视频配置
28 struct CMD_S_VideoConfig
29 {
30     //连接信息
31     WORD                            wNatPort;                            //网络端口
32     WORD                            wLocalPort;                            //网络端口
33     DWORD                            dwNatAddr;                            //网络地址
34     DWORD                            dwLocalAddr;                        //本地地址
35 
36     //用户标识
37     DWORD                            dwLocalUserID;                        //本地用户
38 };
39 
40 //////////////////////////////////////////////////////////////////////////
41 
42 #endif
CMD_Video.h

头文件CMD_Plaza.h:

bubuko.com,布布扣
  1 #ifndef CMD_PLAZA_HEAD_FILE
  2 #define CMD_PLAZA_HEAD_FILE
  3 
  4 //////////////////////////////////////////////////////////////////////////
  5 
  6 //广场版本
  7 #define VER_PLAZA_LOW                    2                                //广场版本
  8 #define VER_PLAZA_HIGH                    5                                //广场版本
  9 #define VER_PLAZA_FRAME                    MAKELONG(VER_PLAZA_LOW,VER_PLAZA_HIGH)
 10 
 11 //大厅安装包名称
 12 #define LEGAME_SETUP                    TEXT("LEGameSetup")
 13 
 14 //////////////////////////////////////////////////////////////////////////
 15 //登录错误标识
 16 
 17 #define ERC_GP_LOGON_SUCCESS            0                                //登陆成功
 18 #define ERC_GP_ACCOUNTS_NOT_EXIST        1                                //帐号不存在
 19 #define ERC_GP_LONG_NULLITY                2                                //禁止登录
 20 #define ERC_GP_PASSWORD_ERCOR            3                                //密码错误
 21 
 22 //////////////////////////////////////////////////////////////////////////
 23 //登录命令码
 24 
 25 #define MDM_GP_LOGON                    1                                //广场登录
 26 
 27 #define SUB_GP_LOGON_ACCOUNTS            1                                //帐号登录
 28 #define SUB_GP_LOGON_USERID                2                                //I D 登录
 29 #define SUB_GP_REGISTER_ACCOUNTS        3                                //注册帐号
 30 
 31 #define SUB_GP_LOGON_SUCCESS            100                                //登陆成功
 32 #define SUB_GP_LOGON_ERROR                101                                //登陆失败
 33 #define SUB_GP_LOGON_FINISH                102                                //登陆完成
 34 #define SUB_GP_UPDATE_USER_INFO            103                                //更新用户信息
 35 #define SUB_GP_UPDATE_USER_INFO_R        104                                //更新用户信息_回发至大厅
 36 #define SUB_GR_GET_OUT_MONEY            105                                //进入游戏房间扣金币
 37 
 38 //帐号登录
 39 struct CMD_GP_LogonByAccounts
 40 {
 41     DWORD                                dwPlazaVersion;                    //广场版本
 42     DWORD                               dwIP;                           //用户IP
 43     TCHAR                                szAccounts[NAME_LEN];            //登录帐号
 44     TCHAR                                szPassWord[PASS_LEN];            //登录密码
 45     TCHAR                                szLocalInfo[CLIENT_INFO_LEN];    //本机信息
 46     TCHAR                                szDestServerInfo[SERVER_NUMBER][50];//服务器信息
 47 };    
 48 
 49 //I D 登录
 50 struct CMD_GP_LogonByUserID
 51 {
 52     DWORD                                dwPlazaVersion;                    //广场版本
 53     DWORD                                dwUserID;                        //用户 I D
 54     TCHAR                                szPassWord[PASS_LEN];            //登录密码
 55 };
 56 
 57 //注册帐号
 58 struct CMD_GP_RegisterAccounts
 59 {
 60     WORD                                wFaceID;                        //头像标识
 61     BYTE                                cbGender;                        //用户性别
 62     DWORD                                dwPlazaVersion;                    //广场版本
 63     TCHAR                                szSpreader[NAME_LEN];            //推广人名
 64     TCHAR                                szAccounts[NAME_LEN];            //登录帐号
 65     TCHAR                                szNickname[NAME_LEN];            //用户昵称
 66     TCHAR                                szPassWord[PASS_LEN];            //登录密码
 67 };
 68 
 69 //登陆成功
 70 struct CMD_GP_LogonSuccess
 71 {
 72     LONG                                lScore;                         //用户积分
 73     LONG                                lGold;                          //用户拍币
 74     LONG                                lPaiCoin;                       //用户元宝
 75     LONG                                lExperience;                    //用户经验
 76     WORD                                wFaceID;                        //头像索引
 77     BYTE                                cbGender;                        //用户性别
 78     DWORD                                dwUserID;                        //用户 I D
 79     DWORD                                dwGameID;                        //游戏 I D
 80 
 81     DWORD                                dwMasterRight;                    //管理权限
 82     BYTE                                cbMasterOrder;                    //管理等级
 83     BYTE                                cbMemberOrder;                    //管理等级
 84     BOOL                                bVip;                            //VIP功能
 85 };
 86 
 87 //登陆失败
 88 struct CMD_GP_LogonError
 89 {
 90     LONG                                lErrorCode;                        //错误代码
 91     TCHAR                                szErrorDescribe[128];            //错误消息
 92 };
 93 
 94 struct CMD_GP_UpdateUserInfo
 95 {
 96     DWORD                                dwUserID;                        //用户ID
 97 };
 98 
 99 struct CMD_GP_UpdateUserInfo_R
100 {
101     DWORD                                dwUserID;                        //用户ID
102     LONG                                lScore;                            //用户分数
103     LONG                                lGold;                            //用户分数
104     LONG                                lPaiCoin;                        //用户分数
105 };
106 //////////////////////////////////////////////////////////////////////////
107 //游戏列表命令码
108 
109 #define MDM_GP_SERVER_LIST                2                                //列表信息
110 
111 #define SUB_GP_LIST_TYPE                100                                //类型列表
112 #define SUB_GP_LIST_KIND                101                                //种类列表
113 #define SUB_GP_LIST_STATION                102                                //站点列表
114 #define SUB_GP_LIST_SERVER                103                                //房间列表
115 #define SUB_GP_LIST_FINISH                104                                //发送完成
116 #define SUB_GP_LIST_CONFIG                105                                //列表配置
117 
118 #define SUB_GP_LIST_PROCESS                106                                //进程列表
119 
120 //列表配置
121 struct CMD_GP_ListConfig
122 {
123     BYTE                                bShowOnLineCount;                //显示人数
124 };
125 
126 //////////////////////////////////////////////////////////////////////////
127 //系统命令码
128 
129 #define MDM_GP_SYSTEM                    3                                //系统命令
130 
131 #define SUB_GP_VERSION                    100                                //版本通知
132 #define SUB_SP_SYSTEM_MSG                101                                //系统消息
133 
134 //版本通知
135 struct CMD_GP_Version
136 {
137     DWORD                                bNewVersion;                    //更新版本
138     BYTE                                bAllowConnect;                    //允许连接
139 };
140 
141 //////////////////////////////////////////////////////////////////////////
142 
143 #endif
CMD_Plaza.h

头文件CMD_Center.h:

bubuko.com,布布扣
 1 #ifndef CMD_CENTER_HEAD_FILE
 2 #define CMD_CENTER_HEAD_FILE
 3 
 4 //
 5 //游戏列表命令码
 6 //
 7 
 8 #define MDM_CS_SERVER_LIST                1                                //列表信息
 9 
10 #define SUB_CS_GET_SERVER_LIST            1                                //请求列表
11 
12 #define SUB_CS_LIST_INFO                100                                //列表信息
13 #define SUB_CS_LIST_TYPE                101                                //类型列表
14 #define SUB_CS_LIST_KIND                102                                //种类列表
15 #define SUB_CS_LIST_STATION                103                                //站点列表
16 #define SUB_CS_LIST_SERVER                104                                //房间列表
17 #define SUB_CS_LIST_FINISH                105                                //列表完成
18 
19 //列表信息
20 struct CMD_CS_ListInfo
21 {
22     DWORD                                dwTypeCount;                    //类型数目
23     DWORD                                dwKindCount;                    //种类数目
24     DWORD                                dwServerCount;                    //房间数目
25     DWORD                                dwStationCount;                    //站点数目
26 };
27 
28 //
29 //房间管理命令码
30 //
31 
32 #define MDM_CS_SERVER_MANAGER            2                                //房间管理
33 
34 #define SUB_CS_REG_GAME_SERVER            1                                //注册房间
35 #define SUB_CS_UNREG_GAME_SERVER        2                                //注销房间
36 #define SUB_CS_SERVER_ONLINE_COUNT        3                                //房间人数
37 
38 //注册房间
39 struct CMD_CS_RegGameServer
40 {
41     tagGameServer                        GameServer;                        //房间信息
42 };
43 
44 //注销房间
45 struct CMD_CS_UnRegGameServer
46 {
47     WORD                                wKindID;                        //名称号码
48     WORD                                wServerID;                        //房间号码
49 };
50 
51 //房间人数
52 struct CMD_CS_ServerOnLineCount
53 {
54     WORD                                wKindID;                        //名称号码
55     WORD                                wServerID;                        //房间号码
56     DWORD                                dwOnLineCount;                    //在线人数
57 };
58 
59 #endif
60 
61 
62 //-----------------------------------------------
63 //                    the end
64 //-----------------------------------------------
CMD_Center.h

头文件SocketModule.h:

bubuko.com,布布扣
  1 #ifndef SOCKET_MODULE_HEAD_FILE
  2 #define SOCKET_MODULE_HEAD_FILE
  3 
  4 //////////////////////////////////////////////////////////////////////////
  5 
  6 //平台头文件
  7 #include "..\..\Include\模板库\Template.h"
  8 #include "..\..\Include\公共文件\GlobalDef.h"
  9 #include "..\..\Include\组件接口\IUnknownEx.h"
 10 
 11 //////////////////////////////////////////////////////////////////////////
 12 //公共宏定义
 13 
 14 //代理类型
 15 #define PROXY_NONE                    0                                    //没有代理
 16 #define PROXY_SOCKS4                1                                    //SOCKS4 代理
 17 #define PROXY_SOCKS5                2                                    //SOCKS5 代理
 18 #define PROXY_HTTP                    3                                    //HTTP 代理
 19 
 20 //模块定义
 21 #ifdef _DEBUG
 22     #define SOCKET_MODULE_DLL_NAME    TEXT("SocketD.dll")            //组件 DLL 名字
 23 #else
 24     #define SOCKET_MODULE_DLL_NAME    TEXT("Socket.dll")            //组件 DLL 名字
 25 #endif
 26 
 27 //////////////////////////////////////////////////////////////////////////
 28 //枚举定义
 29 
 30 //连接状态定义
 31 enum enSocketState
 32 {
 33     SocketState_NoConnect,            //没有连接
 34     SocketState_Connecting,            //正在连接
 35     SocketState_Connected,            //成功连接
 36 };
 37 
 38 //////////////////////////////////////////////////////////////////////////
 39 //结构定义
 40 
 41 //代理信息结构
 42 struct tagProxyInfo
 43 {
 44     BYTE                            cbProxyType;                        //代理类型
 45     WORD                            wProxyPort;                            //代理端口
 46     CString                            strProxyName;                        //代理用户名
 47     CString                            strProxyPass;                        //代理密码
 48     CString                            strProxyServer;                        //代理地址
 49     CString                            strHttpDomain;                        //代理域名
 50 };
 51 
 52 //////////////////////////////////////////////////////////////////////////
 53 
 54 #define VER_IClientSocket INTERFACE_VERSION(5,2)
 55 static const GUID IID_IClientSocket={0x8b0e3918,0x5139,0x48da,0xbf,0x40,0xba,0x95,0xad,0xce,0x59,0x64};
 56 
 57 //网络组件接口
 58 interface IClientSocket : public IUnknownEx
 59 {
 60     //取消代理
 61     virtual void __cdecl CancelProxyServer()=NULL;
 62     //代理服务器
 63     virtual void __cdecl SetProxyServer(tagProxyInfo & ProxyInfo)=NULL;
 64     //设置接口
 65     virtual bool __cdecl SetSocketSink(IUnknownEx * pIUnknownEx)=NULL;
 66     //获取接口
 67     virtual void  * __cdecl GetSocketSink(const IID & Guid, DWORD dwQueryVer)=NULL;
 68     //获取发送间隔
 69     virtual DWORD __cdecl GetLastSendTick()=NULL;
 70     //获取接收间隔
 71     virtual DWORD __cdecl GetLastRecvTick()=NULL;
 72     //获取发送数目
 73     virtual DWORD __cdecl GetSendPacketCount()=NULL;
 74     //获取接收数目
 75     virtual DWORD __cdecl GetRecvPacketCount()=NULL;
 76     //获取状态
 77     virtual enSocketState __cdecl GetConnectState()=NULL;
 78     //连接服务器
 79     virtual bool __cdecl Connect(DWORD dwServerIP, WORD wPort)=NULL;
 80     //连接服务器
 81     virtual bool __cdecl Connect(const LPCTSTR szServerIP, WORD wPort)=NULL;
 82     //发送函数
 83     virtual bool __cdecl SendData(WORD wMainCmdID, WORD wSubCmdID)=NULL;
 84     //发送函数
 85     virtual bool __cdecl SendData(WORD wMainCmdID, WORD wSubCmdID, void * pData, WORD wDataSize)=NULL;
 86     //关闭连接
 87     virtual bool __cdecl CloseSocket(bool bNotify)=NULL;
 88 };
 89 
 90 //////////////////////////////////////////////////////////////////////////
 91 
 92 #define VER_IClientSocketSink INTERFACE_VERSION(5,2)
 93 static const GUID IID_IClientSocketSink={0x55fcf8aa,0x526a,0x44c2,0x9a,0xd1,0x4,0xe,0x7,0xd6,0x8a,0x2a};
 94 
 95 //网络钩子接口
 96 interface IClientSocketSink : public IUnknownEx
 97 {
 98     //网络连接消息
 99     virtual bool __cdecl OnSocketConnect(int iErrorCode, LPCTSTR pszErrorDesc, IClientSocket * pIClientSocke)=NULL;
100     //网络读取消息
101     virtual bool __cdecl OnSocketRead(CMD_Command Command, void * pBuffer, WORD wDataSize, IClientSocket * pIClientSocke)=NULL;
102     //网络关闭消息
103     virtual bool __cdecl OnSocketClose(IClientSocket * pIClientSocke, bool bCloseByServer)=NULL;
104 };
105 
106 //////////////////////////////////////////////////////////////////////////
107 
108 //网络组件辅助类
109 class CClientSocketHelper : public CTempldateHelper<IClientSocket>
110 {
111     //函数定义
112 public:
113     //构造函数
114     CClientSocketHelper(void) : CTempldateHelper<IClientSocket>(IID_IClientSocket,
115         VER_IClientSocket,SOCKET_MODULE_DLL_NAME,TEXT("CreateSocket"))
116     {
117     }
118 };
119 
120 //////////////////////////////////////////////////////////////////////////
121 
122 #endif
SocketModule.h

 

公司的c++游戏数据库连接代码,mark低,希望以后有用^-^

bubuko.com,布布扣

收藏一个c++连接数据库的类

标签:des   android   style   blog   http   io   ar   color   os   

原文地址:http://www.cnblogs.com/vinsonLu/p/4157437.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!