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

模拟服务器

开发平台:

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