诸暨麻将添加redis
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

214 行
5.0 KiB

  1. #include "stdafx.h"
  2. #include "JsonBusiness.h"
  3. using namespace std;
  4. using namespace Json;
  5. //
  6. ////建立对象函数
  7. //extern "C" __declspec(dllexport) void * __cdecl CreateJsonBusiness(const GUID & Guid, DWORD dwInterfaceVer)
  8. //{
  9. // //建立对象
  10. // CJsonBusiness * pJsonBusiness = NULL;
  11. // try
  12. // {
  13. // pJsonBusiness = new CJsonBusiness();
  14. // if (pJsonBusiness == NULL) throw TEXT("创建失败");
  15. // void * pObject = pJsonBusiness->QueryInterface(Guid, dwInterfaceVer);
  16. // if (pObject == NULL) throw TEXT("接口查询失败");
  17. // return pObject;
  18. // }
  19. // catch (...) {}
  20. //
  21. // //清理对象
  22. // SafeDelete(pJsonBusiness);
  23. // return NULL;
  24. //}
  25. CJsonBusiness::CJsonBusiness()
  26. {
  27. m_str = "";
  28. m_wMainCmd = 0;
  29. m_wSubCmd = 0;
  30. m_reader = m_ft;
  31. }
  32. CJsonBusiness::~CJsonBusiness()
  33. {
  34. m_root.clear();
  35. }
  36. void
  37. CJsonBusiness::Clear()
  38. {
  39. m_root.clear();
  40. m_wMainCmd = 0;
  41. m_wSubCmd = 0;
  42. }
  43. std::string
  44. CJsonBusiness::GetNullJson(VOID* pData)
  45. {
  46. m_root.clear();
  47. if (IsVaildPara(pData)){
  48. m_str = m_root.string_To_UTF8("", 4);
  49. }
  50. return m_str;
  51. }
  52. std::string
  53. CJsonBusiness::JsonWriteUTF_8(Value & root)
  54. {
  55. std::string str = "";
  56. str = m_fw.write(root);
  57. m_str = "";
  58. m_str=root.string_To_UTF8(str.c_str(), str.size());
  59. root.clear();
  60. return m_str;
  61. }
  62. void
  63. CJsonBusiness::Log(std::string str)
  64. {
  65. #ifdef _DEBUG
  66. WORD rsize = 0;
  67. TCHAR tString[1024] = L"";
  68. CString cstr;
  69. rsize = m_root.MByteToWChar(str.c_str(), tString, 1024);
  70. cstr.Format(L"主命令-子命令:%d-%d %s", m_wMainCmd, m_wSubCmd, tString);
  71. //提示消息
  72. CTraceService::TraceString(cstr, TraceLevel_Normal);
  73. #endif
  74. }
  75. void
  76. CJsonBusiness::Log(std::string str, const TCHAR* nStr)
  77. {
  78. #ifdef _DEBUG
  79. TCHAR tString[100000] = L"";
  80. CString cstr=L"";
  81. m_root.MByteToWChar(str.c_str(), tString, str.size()+1);
  82. cstr.Format(L"消息注释:%s,主命令-子命令:%d-%d %s", nStr, m_wMainCmd, m_wSubCmd, tString);
  83. //提示消息
  84. CTraceService::TraceString(cstr, TraceLevel_Normal);
  85. #endif
  86. }
  87. // 检验是否包含特殊字符
  88. bool
  89. CJsonBusiness::checkNumber(string str)
  90. {
  91. int badNum = 0;
  92. int size = str.length();
  93. if (size <= 0)
  94. return false;
  95. char* pStr = new char[size+1];
  96. strcpy(pStr, str.c_str());
  97. for (int i = 0; i < size; i++)
  98. {
  99. if (!(pStr[i] >= 48 && pStr[i] <= 57))//数字符号
  100. continue;
  101. if (ispunct(pStr[i]))
  102. {
  103. badNum++;
  104. }
  105. }
  106. delete[] pStr;
  107. pStr = NULL;
  108. bool res = true;
  109. if (badNum > 0)
  110. {
  111. res = false;
  112. }
  113. return res;
  114. }
  115. //闲聊分享战绩
  116. std::string CJsonBusiness::GetInfoJson(const DWORD GameID,const TCHAR WanFInfo[68],const std::string strTime,const std::string strMd5, DBR_GR_ClubRecordXianLiao FenXiangRecord)
  117. {
  118. if (IsVaildPara(&FenXiangRecord))
  119. {
  120. m_str = m_root.string_To_UTF8("1000", JSON_BUSINESS_ERROR_SIZE);
  121. return "";
  122. }
  123. if (FenXiangRecord.dwClubID == 0 || FenXiangRecord.dwTableID == 0)return "";
  124. TCHAR WanFTitle[68];
  125. CopyMemory(WanFTitle, WanFInfo, sizeof(WanFTitle));
  126. string str = "";
  127. m_root.clear();
  128. m_root.WCharToMByte(WanFTitle, str, CountArray(WanFTitle));//玩法内容
  129. m_root["Title"] = Value(str);
  130. m_root["ClubID"] = Value((INT)FenXiangRecord.dwClubID);
  131. m_root["GameID"] = Value((INT)GameID);
  132. m_root["Time"] = Value(strTime);
  133. m_root["Sign"] = Value(strMd5);
  134. Value rootPlayers;
  135. for (BYTE i = 0; i < FenXiangRecord.dwUserCount; i++)
  136. {
  137. str = "";
  138. rootPlayers.WCharToMByte(FenXiangRecord.Player[i].szImgHead, str, CountArray(FenXiangRecord.Player[i].szImgHead));
  139. rootPlayers["HeadImg"] = Value(str);
  140. str = "";
  141. rootPlayers.WCharToMByte(FenXiangRecord.Player[i].szName, str, CountArray(FenXiangRecord.Player[i].szName));
  142. rootPlayers["NickName"] = Value(str);
  143. rootPlayers["UserID"] = Value(FenXiangRecord.Player[i].userID);
  144. rootPlayers["GetScore"] = Value(FenXiangRecord.Player[i].gScore);
  145. m_root["Players"].append(Value(rootPlayers));
  146. }
  147. str = "";
  148. str = m_fw.write(m_root);
  149. m_str = m_root.string_To_UTF8(str.c_str(), str.size());
  150. m_root.clear();
  151. return m_str;
  152. }
  153. std::string
  154. CJsonBusiness::GetInfoJson(TCHAR* ptr, DWORD size) {
  155. if (IsVaildPara(ptr))
  156. {
  157. m_str = m_root.string_To_UTF8("1000", JSON_BUSINESS_ERROR_SIZE);
  158. return "";
  159. }
  160. TCHAR* pData = (TCHAR*)malloc(size * sizeof(TCHAR));
  161. ZeroMemory(pData, size * sizeof(TCHAR));
  162. CopyMemory(pData, ptr, size * sizeof(TCHAR));
  163. std::string str = "";
  164. m_root.WCharToMByte(pData, str, size * sizeof(TCHAR));
  165. if (MDM_GR_USER == m_wMainCmd)
  166. {
  167. switch (m_wSubCmd)
  168. {
  169. case SUB_GR_USER_GET_DINGDANLISTACK:
  170. m_root["reqzhifu"] = Value(str);
  171. break;
  172. case SUB_GR_USER_GET_BANGDINGACK:
  173. {
  174. CMD_GR_BangDingACK* ptr = (CMD_GR_BangDingACK*)pData;
  175. m_root["bRet"] = Value((BYTE)ptr->bRet);
  176. m_root["bLen"] = Value((BYTE)ptr->bLen);
  177. std::string strt = "";
  178. m_root.WCharToMByte(ptr->szText, strt, CountArray(ptr->szText) * sizeof(TCHAR));
  179. m_root["szText"] = Value(strt);
  180. break;
  181. }
  182. default:
  183. m_str = "";
  184. free((void*)pData);
  185. return m_str;
  186. }
  187. }
  188. m_str = JsonWriteUTF_8(m_root);
  189. free((void*)pData);
  190. pData = NULL;
  191. return m_str;
  192. }