S3DBInterface.h
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:16k
源码类别:

模拟服务器

开发平台:

C/C++

  1. //#include "kstdafx.h"
  2. #ifndef S3DBINTERFACE_H
  3. #define S3DBINTERFACE_H
  4. #define IN
  5. #define OUT
  6. #include <map>
  7. #include <string>
  8. #include <vector>
  9. #define SAVE_ITEM_MAGICATTRIB_TO_DB
  10. #ifndef MAGICATTRIB
  11. #define MAGICATTRIB
  12. struct KMagicAttrib
  13. {
  14. int nAttribType; //属性类型
  15. int nValue[3]; //属性参数
  16. KMagicAttrib(){nValue[0] = nValue[1] = nValue[2] = nAttribType = 0;};
  17. };
  18. #else
  19. struct KMagicAttrib;
  20. #endif
  21. class KTabFileCtrl;
  22. class KIniFile;
  23. struct TIntDBValue
  24. {
  25. BYTE btUnitType;
  26. };
  27. struct TRoleBaseInfo
  28. {
  29. //RoleBaseInfo
  30. DWORD dwId;
  31. char szName[100];
  32. bool bSex;
  33. char szAlias[100];
  34. char caccname[100]                   ;
  35. BYTE nFirstSect;
  36. BYTE nSect;
  37. int ijoincount                     ;
  38. int isectrole                      ;
  39. int igroupcode                     ;
  40. int igrouprole                     ;
  41. int irevivalid                     ;
  42. char cpartnercode[100]                   ;
  43. int isavemoney                                     ;
  44. int imoney                                         ;
  45. int ifiveprop                      ;
  46. int iteam                          ;
  47. int ifightlevel                    ;
  48. int fightexp                      ;
  49. int ileadlevel                     ;
  50. int ileadexp                       ;
  51. int iliveexp                       ;
  52. int ipower                         ;
  53. int iagility                       ;
  54. int iouter                         ;
  55. int iinside                        ;
  56. int iluck                          ;
  57. int imaxlife                       ;
  58. int imaxstamina                    ;
  59. int imaxinner                      ;
  60. int ileftprop                      ;
  61. int ileftfight                     ;
  62. int ileftlife                      ;
  63. int ifinishgame                    ;
  64. int irevivalx                      ;
  65. int irevivaly                      ;
  66. short iarmorres                      ;
  67. short iweaponres                     ;
  68. short ihelmres                       ;
  69. };
  70. struct TRoleData
  71. {
  72. TRoleBaseInfo BaseInfo;
  73. bool bBaseNeedUpdate;//通知是否需要更新
  74. //当存取时如果Offset等于-1,表示不更新该数据
  75. //Additional Info
  76. short nFightSkillCount;
  77. short nLiveSkillCount;
  78. BYTE nTaskCount;
  79. short nItemCount;
  80. short nFriendCount;
  81. int dwTaskOffset;
  82. int dwLSkillOffset;
  83. int dwFSkillOffset;
  84. int dwItemOffset;
  85. int dwFriendOffset;
  86. int dwDataLen;
  87. BYTE pBuffer[1];
  88. };
  89. struct TDBTaskData
  90. {
  91. BYTE m_nTaskId;
  92. short m_nTaskValue;
  93. };
  94. struct TDBItemData
  95. {
  96. //BaseInfo
  97. int iid;
  98. char cusercode[100];
  99. int iequipclasscode;
  100. int ilocal                                      ;
  101. int ix                                            ;
  102. int iy                                            ;
  103. int iequipcode                                     ;
  104. int idetailtype                    ;
  105. int iparticulartype                ;
  106. int ilevel                         ;
  107. int iseries                        ;
  108. int iequipversion                  ;
  109. int irandseed                      ;
  110. int iparam2                        ;
  111. int iparam3                        ;
  112. int iparam5                        ;
  113. int iparam4                        ;
  114. int iparam6                        ;
  115. int iparam1                        ;
  116. int ilucky                         ;
  117. #ifdef SAVE_ITEM_MAGICATTRIB_TO_DB
  118. BYTE BaseInfoCount;
  119. BYTE EfficCount;
  120. BYTE RequireInfoCount;
  121. BYTE pBuffer[1];
  122. #endif
  123. };
  124. struct TDBFriendsData
  125. {
  126. short FriendCount;
  127. void * pBuffer;
  128. short Offset[1];
  129. };
  130. struct TDBSkillData
  131. {
  132. short m_nSkillId;
  133. short m_nSkillLevel;
  134. };
  135. enum 
  136. {
  137. /*==============================================================*/
  138. /* Table: EquipBaseInfo                                         */
  139. /*==============================================================*/
  140.    EQUIPBASEINFO_IID                                             ,
  141.    EQUIPBASEINFO_IMAINID                                        ,
  142.    EQUIPBASEINFO_ICLASS                                      ,
  143.    EQUIPBASEINFO_IVALUE1                        ,
  144.    EQUIPBASEINFO_IVALUE2                        ,
  145.    EQUIPBASEINFO_IVALUE3                        ,
  146. /*==============================================================*/
  147. /* TABLE: EQUIPEFFICINFO_                                        */
  148. /*==============================================================*/
  149.    EQUIPEFFICINFO_IID                                             ,
  150.    EQUIPEFFICINFO_IMAINID                                        ,
  151.    EQUIPEFFICINFO_ICLASS                                      ,
  152.    EQUIPEFFICINFO_IVALUE1                        ,
  153.    EQUIPEFFICINFO_IVALUE2                        ,
  154.    EQUIPEFFICINFO_IVALUE3                        ,
  155. /*==============================================================*/
  156. /* TABLE: EQUIPREQUIREINFO_                                     */
  157. /*==============================================================*/
  158.    EQUIPREQUIREINFO_IID                                             ,
  159.    EQUIPREQUIREINFO_IMAINID                                        ,
  160.    EQUIPREQUIREINFO_ICLASS                                      ,
  161.    EQUIPREQUIREINFO_IVALUE1                        ,
  162.    EQUIPREQUIREINFO_IVALUE2                        ,
  163.    EQUIPREQUIREINFO_IVALUE3                        ,
  164. /*==============================================================*/
  165. /* TABLE: EQUIPMENTS                                            */
  166. /*==============================================================*/
  167.    EQUIPMENTS_IID                                             ,
  168.    EQUIPMENTS_CUSERCODE                                         ,
  169.    EQUIPMENTS_IEQUIPCLASSCODE                                   ,
  170.    EQUIPMENTS_ILOCAL                                      ,
  171.    EQUIPMENTS_IX                                            ,
  172.    EQUIPMENTS_IY                                            ,
  173.    EQUIPMENTS_IEQUIPCODE                                     ,
  174.    EQUIPMENTS_IDETAILTYPE                    ,
  175.    EQUIPMENTS_IPARTICULARTYPE                ,
  176.    EQUIPMENTS_ILEVEL                         ,
  177.    EQUIPMENTS_ISERIES                        ,
  178.    EQUIPMENTS_IEQUIPVERSION                  ,
  179.    EQUIPMENTS_IRANDSEED                      ,
  180.    EQUIPMENTS_IPARAM2                        ,
  181.    EQUIPMENTS_IPARAM3                        ,
  182.    EQUIPMENTS_IPARAM5                        ,
  183.    EQUIPMENTS_IPARAM4                        ,
  184.    EQUIPMENTS_IPARAM6                        ,
  185.    EQUIPMENTS_IPARAM1                        ,
  186.    EQUIPMENTS_ILUCKY                         ,
  187.  
  188. /*==============================================================*/
  189. /* TABLE: FIGHTSKILL                                            */
  190. /*==============================================================*/
  191.    FIGHTSKILL_IID                                             ,
  192.    FIGHTSKILL_CUSERCODE                                         ,
  193.    FIGHTSKILL_IFIGHTSKILL                                 ,
  194.    FIGHTSKILL_IFIGHTSKILLLEVEL                            ,
  195. /*==============================================================*/
  196. /* TABLE: FRIENDLIST_                                           */
  197. /*==============================================================*/
  198.    FRIENDLIST_IID                                             ,
  199.    FRIENDLIST_CUSERCODE                                         ,
  200.    FRIENDLIST_CFRIENDCODE                                       ,
  201. /*==============================================================*/
  202. /* TABLE: LIFESKILL                                             */
  203. /*==============================================================*/
  204.    LIFESKILL_IID                                             ,
  205.    LIFESKILL_CUSERCODE                                         ,
  206.    LIFESKILL_ILIFESKILL                                  ,
  207.    LIFESKILL_ILIFESKILLLEVEL                             ,
  208. /*==============================================================*/
  209. /* TABLE: ROLEINFO                                             */
  210. /*==============================================================*/
  211.    ROLEINFO_IID                                             ,
  212.    ROLEINFO_CUSERCODE                                         ,
  213.    ROLEINFO_BSEX                                            ,
  214.    ROLEINFO_CALIAS                         ,
  215.    ROLEINFO_IFIRSTSECT                     ,
  216.    ROLEINFO_ISECT                          ,
  217.    ROLEINFO_IJOINCOUNT                     ,
  218.    ROLEINFO_ISECTROLE                      ,
  219.    ROLEINFO_IGROUPCODE                     ,
  220.    ROLEINFO_IGROUPROLE                     ,
  221.    ROLEINFO_IREVIVALID                     ,
  222.    ROLEINFO_CPARTNERCODE                   ,
  223.    ROLEINFO_ISAVEMONEY                                     ,
  224.    ROLEINFO_IMONEY                                         ,
  225.    ROLEINFO_IFIVEPROP                      ,
  226.    ROLEINFO_ITEAM                          ,
  227.    ROLEINFO_IFIGHTLEVEL                    ,
  228.    ROLEINFO_FIGHTEXP                      ,
  229.    ROLEINFO_ILEADLEVEL                     ,
  230.    ROLEINFO_ILEADEXP                       ,
  231.    ROLEINFO_ILIVEEXP                       ,
  232.    ROLEINFO_IPOWER                         ,
  233.    ROLEINFO_IAGILITY                       ,
  234.    ROLEINFO_IOUTER                         ,
  235.    ROLEINFO_IINSIDE                        ,
  236.    ROLEINFO_ILUCK                          ,
  237.    ROLEINFO_IMAXLIFE                       ,
  238.    ROLEINFO_IMAXSTAMINA                    ,
  239.    ROLEINFO_IMAXINNER                      ,
  240.    ROLEINFO_ILEFTPROP                      ,
  241.    ROLEINFO_ILEFTFIGHT                     ,
  242.    ROLEINFO_ILEFTLIFE                      ,
  243.    ROLEINFO_CACCNAME                       ,
  244.    ROLEINFO_IFINISHGAME                    ,
  245.    ROLEINFO_DLOGINTIME                     ,
  246.    ROLEINFO_DBEGINDATE                     ,
  247.    ROLEINFO_DENDDATE                       ,
  248.    ROLEINFO_IREVIVALX                      ,
  249.    ROLEINFO_IREVIVALY                      ,
  250.    ROLEINFO_IARMORRES                      ,
  251.    ROLEINFO_IWEAPONRES                     ,
  252.    ROLEINFO_IHELMRES                       ,
  253. /*==============================================================*/
  254. /* TABLE: TASKLIST                                             */
  255. /*==============================================================*/
  256.    TASKLIST_IID                                             ,
  257.    TASKLIST_CUSERCODE                                         ,
  258.    TASKLIST_ITASKCODE                                   ,
  259.    TASKLIST_IDEGREE                                     ,
  260. };
  261. // Ini文件各字段定义---------------------------------------------------
  262. #define SECTION_ROLE "ROLE"
  263. #define SECTION_ITEMLIST "ITEMS"
  264. #define SECTION_ITEM "ITEM" // + id
  265. #define KEY_COUNT "COUNT"
  266. #define KEY_BASELIST "BLISTS"
  267. #define KEY_EFFICLIST "ELISTS"
  268. #define KEY_REQUIRELIST "RLISTS"
  269. #define SECTION_BASEINFO "IB" //IB1_2
  270. #define SECTION_EFFICEINFO "IE"
  271. #define SECTION_REQUIREINFO "IR"
  272. #define SECTION_FRIENDLIST "FRIENDS"
  273. #define KEY_FRIEND "F" // + id
  274. #define SECTION_TASKLIST "TASKS"
  275. #define KEY_TASKID "T" // + id
  276. #define KEY_TASKVALUE "V" // + id
  277. #define SECTION_FIGHTSKILLLIST "FSKILLS"
  278. #define KEY_FIGHTSKILL "S"
  279. #define KEY_FIGHTSKILLLEVEL "L"
  280. #define SECTION_LIFESKILLLIST "LSKILLS"
  281. #define KEY_LIFESKILL "S" // + id
  282. #define KEY_LIFESKILLLEVEL "L" // + id
  283. //------------------------------------------------------------------------------
  284. #pragma warning (disable: 4512)
  285. #pragma warning (disable: 4786)
  286. #ifdef S3DBINTERFACE_EXPORTS
  287. #define S3DBI_API __declspec(dllexport)
  288. #else
  289. #define S3DBI_API __declspec(dllimport)
  290. #endif
  291. //
  292. struct S3DBI_RoleBaseInfo
  293. {
  294. char szRoleName[32];
  295. int  nSex;
  296. int  nHelmType;
  297. int  nArmorType;
  298. int  nWeaponType;
  299. int  nLevel;
  300. };
  301. struct S3DBI_DATAS
  302. {
  303. char * strNames;
  304. char * strValues;
  305. int    nDataNum;
  306. };
  307. enum  S3DBI_TABLENAME
  308. {
  309. TABLE_ACCOUNT,
  310. TABLE_CARD,
  311. TABLE_EQUIPBASEINFO,
  312. TABLE_EQUIPEFFICINFO,
  313. TABLE_EQUIPMENT,
  314. TABLE_EQUIPREQUIREINFO,
  315. TABLE_FIGHTSKILL,
  316. TABLE_FRIEND,
  317. TABLE_LIFESKILL,
  318. TABLE_LIST,
  319. TABLE_ROLE,
  320. TABLE_TASK,
  321. TABLE_TASK_LIST,
  322. };
  323. enum S3DBI_LISTNAME
  324. {
  325. LIST_TASK,
  326. LIST_FRIEND,
  327. LIST_FIGHT,
  328. LIST_LIFESKILL,
  329. LIST_EQUIPMENT,
  330. LIST_EQUIPMENTREQINFO,
  331. LIST_EQUIPMENTBASEINFO,
  332. LIST_EQUIPMENTEFFICINFO,
  333. };
  334. /*
  335. extern DBTableKeyMap  g_RoleTableKeyMap;
  336. typedef std::map<std::string, int> DBTableKeyMap;
  337. typedef std::map<int, std::string> DBStringMap;
  338. typedef std::map<int, int> DBIntegerMap;
  339. */
  340. /*struct TDBTaskData
  341. {
  342. int m_nTaskId;
  343. int m_nTaskValue;
  344. };
  345. struct TDBTableData
  346. {
  347. DBStringMap m_StringDatas;
  348. DBIntegerMap m_IntegerDatas;
  349. };
  350. struct TDBEquiptData;
  351. typedef std::vector<KMagicAttrib> TMagicAttribArray;
  352. typedef std::vector<TDBEquiptData> TDBEquiptArray;
  353. typedef std::vector<TDBSkillData> TDBSkillArray;
  354. typedef std::vector<std::string> TDBFriendArray;
  355. typedef std::vector<TDBTaskData> TDBTaskArray;
  356. extern DBTableKeyMap g_TableIntegerKeyMap;
  357. extern DBTableKeyMap g_TableStringKeyMap;
  358. struct TDBEquiptData : TDBTableData
  359. {
  360. TMagicAttribArray m_mapRequestInfo;
  361. TMagicAttribArray m_mapBaseInfo;
  362. TMagicAttribArray m_mapEfficInfo;
  363. };
  364. struct TDBPlayerData :TDBTableData
  365. {
  366. TDBEquiptArray m_mapEquipt;
  367. TDBSkillArray m_mapFightSkill;
  368. TDBSkillArray m_mapLiveSkill;
  369. TDBFriendArray m_mapFriend;
  370. TDBTaskArray m_mapTask;
  371. };
  372. */
  373. #define S3_DB_TABLENAME  S3DBI_TABLENAME
  374. S3DBI_API int S3DBI_InitDBInterface(); //初始化数据库引擎
  375. S3DBI_API void S3DBI_ReleaseDBInterface(); //释放数据库引擎
  376. //获得角色的信息并以Ini文件的格式放置
  377. //S3DBI_API int S3DBI_GetRoleInfo(IN char * strUser, IN OUT KIniFile * pIniFile);
  378. S3DBI_API void * S3DBI_GetRoleInfo(IN OUT BYTE * pRoleBuffer, IN char * strUser, IN OUT int &nBufLen);
  379. //保存角色的信息,如果数据库不存在该玩家,则增加该玩家
  380. //bAutoInsertWhenNoExistUser 设为TRUE时表示,如果需要保存的该玩家在数据库中并不存在则自动加入到数据库中,FALSE则不增加直接返回错误
  381. //注意INI文件只须存放将需要改动的数据,不需改动的数据将自动保存原状。
  382. S3DBI_API int S3DBI_SaveRoleInfo(IN BYTE * pRoleBuffer, IN char * strUser, BOOL bAutoInsertWhenNoExistUser);
  383. S3DBI_API void S3DBI_ShowDebugInfo(IN BYTE * pRoleBuffer, char * pShowString);
  384. S3DBI_API int S3DBI_GetRoleListOfAccount(char * szAccountName, S3DBI_RoleBaseInfo * RoleBaseList, int nMaxCount);
  385. //删除角色
  386. S3DBI_API int S3DBI_DeleteRole(char * strUser);
  387. S3DBI_API void* S3DBI_GetList(S3DBI_LISTNAME listname,  char * strUser);
  388. S3DBI_API void* S3DBI_GetList(S3DBI_LISTNAME listname,  int iid);
  389. //S3DBI_API int S3DBI_GetListData(S3DBI_LISTNAME listname, void * pList, int i , ColumnAndValue &cav);
  390. S3DBI_API int S3DBI_GetCountOfList(S3DBI_LISTNAME listname, void * pList);
  391. //S3DBI_API int S3DBI_UpdateDataAtList(S3DBI_LISTNAME listname, void * pList, int i , ColumnAndValue &cav);
  392. S3DBI_API int S3DBI_DeleteDataAtList(S3DBI_LISTNAME listname, void * pList, int i );
  393. //S3DBI_API int S3DBI_InsertDataAtList(S3DBI_LISTNAME listname, void * pList, ColumnAndValue cav);
  394. S3DBI_API void S3DBI_ReleaseListBuffer(S3DBI_LISTNAME listname, void * pList);
  395. S3DBI_API int S3DBI_ClearList(S3DBI_LISTNAME listname, void * pList);
  396. //S3DBI_API int S3DBI_GetData(S3_DB_TABLENAME tablename, int nId, ColumnAndValue *pcav);
  397. //S3DBI_API int S3DBI_GetData(S3_DB_TABLENAME tablename, char * strUser , ColumnAndValue * pCav);
  398. //S3DBI_API int S3DBI_UpdateData(S3_DB_TABLENAME tablename, int nId, ColumnAndValue *pcav);
  399. //S3DBI_API int S3DBI_UpdateData(S3_DB_TABLENAME tablename, char * strUser, ColumnAndValue *pcav);
  400. S3DBI_API int S3DBI_DeleteData(S3_DB_TABLENAME tablename, int nId);
  401. S3DBI_API int S3DBI_DeleteData(S3_DB_TABLENAME tablename, char * strUser);
  402. //S3DBI_API int S3DBI_InsertData(S3_DB_TABLENAME tablename, int nId, ColumnAndValue cav);
  403. //S3DBI_API int S3DBI_InsertData(S3_DB_TABLENAME tablename, char * strUser, ColumnAndValue cav);
  404. S3DBI_API int S3DBI_GetListData(S3DBI_LISTNAME listname, void * pList, int i , KTabFileCtrl *pTabFile);
  405. S3DBI_API int S3DBI_DeleteDataAtList(S3DBI_LISTNAME listname, void * pList, int i );
  406. S3DBI_API int S3DBI_InsertDataAtList(S3DBI_LISTNAME listname, void * pList, KTabFileCtrl *pTabFile);
  407. S3DBI_API int S3DBI_GetData(S3_DB_TABLENAME tablename, int nId, KTabFileCtrl *pTabFile);
  408. S3DBI_API int S3DBI_GetData(S3_DB_TABLENAME tablename, char * strUser, KTabFileCtrl * pTabFile);
  409. S3DBI_API int S3DBI_UpdateData(S3_DB_TABLENAME tablename, int nId, KTabFileCtrl *pTabFile);
  410. S3DBI_API int S3DBI_UpdateData(S3_DB_TABLENAME tablename, char * strUser, KTabFileCtrl *pTabFile);
  411. S3DBI_API int S3DBI_InsertData(S3_DB_TABLENAME tablename,  KTabFileCtrl *pTabFile);
  412. #endif