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

模拟服务器

开发平台:

C/C++

  1. // TongConnect.cpp: implementation of the CTongConnect class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "TongConnect.h"
  6. #include "TongServer.h"
  7. #include "S3Relay.h"
  8. #include "Global.h"
  9. #include "malloc.h"
  10. //-------------------------- tong struct size ---------------------------
  11. int g_nTongPSSize[defTONG_PROTOCOL_SERVER_NUM] = 
  12. {
  13. -1, // enumC2S_TONG_CREATE
  14. -1, // enumC2S_TONG_ADD_MEMBER
  15. sizeof(STONG_GET_TONG_HEAD_INFO_COMMAND), // enumC2S_TONG_GET_HEAD_INFO
  16. sizeof(STONG_GET_MANAGER_INFO_COMMAND), // enumC2S_TONG_GET_MANAGER_INFO
  17. sizeof(STONG_GET_MEMBER_INFO_COMMAND), // enumC2S_TONG_GET_MEMBER_INFO
  18. sizeof(STONG_INSTATE_COMMAND), // enumC2S_TONG_INSTATE
  19. sizeof(STONG_KICK_COMMAND), // enumC2S_TONG_KICK
  20. sizeof(STONG_LEAVE_COMMAND), // enumC2S_TONG_LEAVE
  21. sizeof(STONG_CHANGE_MASTER_COMMAND), // enumC2S_TONG_CHANGE_MASTER
  22. sizeof(STONG_ACCEPT_MASTER_COMMAND), // enumC2S_TONG_ACCEPT_MASTER
  23. sizeof(STONG_GET_LOGIN_DATA_COMMAND), // enumC2S_TONG_GET_LOGIN_DATA
  24. };
  25. //------------------------- tong struct size end ---------------------------
  26. //////////////////////////////////////////////////////////////////////
  27. // Construction/Destruction
  28. //////////////////////////////////////////////////////////////////////
  29. CTongConnect::CTongConnect(CTongServer* pTongServer, unsigned long id)
  30. : CNetConnect(pTongServer, id)
  31. {
  32. }
  33. CTongConnect::~CTongConnect()
  34. {
  35. }
  36. void CTongConnect::OnClientConnectCreate()
  37. {
  38. rTRACE("tong connect create: %s", _ip2a(GetIP()));
  39. }
  40. void CTongConnect::OnClientConnectClose()
  41. {
  42. rTRACE("tong connect close: %s", _ip2a(GetIP()));
  43. }
  44. void CTongConnect::RecvPackage(const void* pData, size_t size)
  45. {
  46. EXTEND_HEADER* pHeader = (EXTEND_HEADER*)pData;
  47. if (pHeader->ProtocolFamily == pf_tong)
  48. {
  49. Proc0_Tong(pData, size);
  50. }
  51. else if (pHeader->ProtocolFamily == pf_friend)
  52. {
  53. Proc0_Friend(pData, size);
  54. }
  55. }
  56. BOOL CTongConnect::PassToSomeone(DWORD ip, unsigned long id, DWORD nameid, const void* pData, size_t size)
  57. {
  58. CNetConnectDup conndup;
  59. if (GetIP() == ip)
  60. conndup = *this;
  61. else
  62. {
  63. conndup = g_TongServer.FindTongConnectByIP(ip);
  64. if (!conndup.IsValid())
  65. return FALSE;
  66. }
  67. size_t pckgsize = sizeof(EXTEND_PASSTOSOMEONE) + size;
  68. EXTEND_PASSTOSOMEONE* pEps = (EXTEND_PASSTOSOMEONE*)_alloca(pckgsize);
  69. pEps->ProtocolFamily = pf_extend;
  70. pEps->ProtocolID = extend_s2c_passtosomeone;
  71. pEps->nameid = nameid;
  72. pEps->lnID = id;
  73. pEps->datasize = size;
  74. memcpy(pEps + 1, pData, size);
  75. conndup.SendPackage(pEps, pckgsize);
  76. return TRUE;
  77. }
  78. //--------------------------------------------------------------------
  79. // 功能:帮会协议处理,收到 game server 发来的与帮会有关的协议
  80. //--------------------------------------------------------------------
  81. void CTongConnect::Proc0_Tong(const void* pData, size_t size)
  82. {
  83. if (!pData)
  84. return;
  85. // 协议长度检测
  86. if (size < sizeof(EXTEND_HEADER))
  87. return;
  88. EXTEND_HEADER* pHeader = (EXTEND_HEADER*)pData;
  89. if (pHeader->ProtocolID >= enumC2S_TONG_NUM)
  90. return;
  91. if (g_nTongPSSize[pHeader->ProtocolID] < 0)
  92. {
  93. if (size <= sizeof(EXTEND_HEADER) + 2)
  94. return;
  95. WORD wLength = *((WORD*)((BYTE*)pData + sizeof(EXTEND_HEADER)));
  96. if (wLength != size)
  97. return;
  98. }
  99. else if (g_nTongPSSize[pHeader->ProtocolID] != size)
  100. {
  101. return;
  102. }
  103. switch (pHeader->ProtocolID)
  104. {
  105. case enumC2S_TONG_CREATE:
  106. {
  107. char szPlayerName[64], szTongName[64];
  108. STONG_CREATE_COMMAND *pTongCreate = (STONG_CREATE_COMMAND*)pData;
  109. int nCamp = pTongCreate->m_btCamp;
  110. memcpy(szTongName, &pTongCreate->m_szBuffer[0], pTongCreate->m_btTongNameLength);
  111. szTongName[pTongCreate->m_btTongNameLength] = 0;
  112. memcpy(szPlayerName, &pTongCreate->m_szBuffer[pTongCreate->m_btTongNameLength], pTongCreate->m_btPlayerNameLength);
  113. szPlayerName[pTongCreate->m_btPlayerNameLength] = 0;
  114. // 建立帮会
  115. int nErrorID = g_cTongSet.Create(nCamp, szPlayerName, szTongName);
  116. if (nErrorID == 0)
  117. {
  118. STONG_CREATE_SUCCESS_SYNC sSync;
  119. sSync.ProtocolFamily = pf_tong;
  120. sSync.ProtocolID = enumS2C_TONG_CREATE_SUCCESS;
  121. sSync.m_dwPlayerNameID = pTongCreate->m_dwPlayerNameID;
  122. sSync.m_dwParam = pTongCreate->m_dwParam;
  123. sSync.m_btCamp = pTongCreate->m_btCamp;
  124. sSync.m_btTongNameLength = pTongCreate->m_btTongNameLength;
  125. memcpy(sSync.m_szTongName, pTongCreate->m_szBuffer, sSync.m_btTongNameLength);
  126. sSync.m_wLength = sizeof(STONG_CREATE_SUCCESS_SYNC) - sizeof(sSync.m_szTongName) + sSync.m_btTongNameLength;
  127. this->SendPackage((const void *)&sSync, sSync.m_wLength);
  128. }
  129. // 建立失败
  130. else
  131. {
  132. STONG_CREATE_FAIL_SYNC sSync;
  133. sSync.ProtocolFamily = pf_tong;
  134. sSync.ProtocolID = enumS2C_TONG_CREATE_FAIL;
  135. sSync.m_dwPlayerNameID = pTongCreate->m_dwPlayerNameID;
  136. sSync.m_dwParam = pTongCreate->m_dwParam;
  137. sSync.m_btFailID = nErrorID;
  138. this->SendPackage((const void *)&sSync, sizeof(STONG_CREATE_FAIL_SYNC));
  139. }
  140. }
  141. break;
  142. // 添加成员
  143. case enumC2S_TONG_ADD_MEMBER:
  144. {
  145. char szPlayerName[64], szTongName[64];
  146. STONG_ADD_MEMBER_COMMAND *pAdd = (STONG_ADD_MEMBER_COMMAND*)pData;
  147. memcpy(szTongName, &pAdd->m_szBuffer[0], pAdd->m_btTongNameLength);
  148. szTongName[pAdd->m_btTongNameLength] = 0;
  149. memcpy(szPlayerName, &pAdd->m_szBuffer[pAdd->m_btTongNameLength], pAdd->m_btPlayerNameLength);
  150. szPlayerName[pAdd->m_btPlayerNameLength] = 0;
  151. int nRet = g_cTongSet.AddMember(szPlayerName, szTongName);
  152. // 成员添加成功
  153. if (nRet >= 0)
  154. {
  155. STONG_ADD_MEMBER_SUCCESS_SYNC sSync;
  156. sSync.ProtocolFamily = pf_tong;
  157. sSync.ProtocolID = enumS2C_TONG_ADD_MEMBER_SUCCESS;
  158. sSync.m_dwPlayerNameID = pAdd->m_dwPlayerNameID;
  159. sSync.m_dwParam = pAdd->m_dwParam;
  160. sSync.m_btCamp = g_cTongSet.GetTongCamp(nRet);
  161. g_cTongSet.GetMasterName(nRet, sSync.m_szMasterName);
  162. g_cTongSet.GetMemberTitle(nRet, sSync.m_szTitleName);
  163. strcpy(sSync.m_szTongName, szTongName);
  164. this->SendPackage((const void *)&sSync, sizeof(sSync));
  165. }
  166. // 成员添加不成功
  167. else
  168. {
  169. STONG_ADD_MEMBER_FAIL_SYNC sSync;
  170. sSync.ProtocolFamily = pf_tong;
  171. sSync.ProtocolID = enumS2C_TONG_ADD_MEMBER_FAIL;
  172. sSync.m_dwPlayerNameID = pAdd->m_dwPlayerNameID;
  173. sSync.m_dwParam = pAdd->m_dwParam;
  174. sSync.m_btFailID = nRet;
  175. this->SendPackage((const void *)&sSync, sizeof(STONG_ADD_MEMBER_FAIL_SYNC));
  176. }
  177. }
  178. break;
  179. // 获得帮会信息
  180. case enumC2S_TONG_GET_HEAD_INFO:
  181. {
  182. STONG_GET_TONG_HEAD_INFO_COMMAND *pGet = (STONG_GET_TONG_HEAD_INFO_COMMAND*)pData;
  183. STONG_HEAD_INFO_SYNC sInfo;
  184. if (g_cTongSet.GetTongHeadInfo(pGet->m_dwTongNameID, &sInfo))
  185. {
  186. sInfo.m_dwParam = pGet->m_dwParam;
  187. sInfo.m_dwNpcID = pGet->m_dwNpcID;
  188. this->SendPackage((const void *)&sInfo, sInfo.m_wLength);
  189. }
  190. }
  191. break;
  192. case enumC2S_TONG_GET_MANAGER_INFO:
  193. {
  194. STONG_GET_MANAGER_INFO_COMMAND *pGet = (STONG_GET_MANAGER_INFO_COMMAND*)pData;
  195. STONG_MANAGER_INFO_SYNC sInfo;
  196. if (g_cTongSet.GetTongManagerInfo(pGet, &sInfo))
  197. this->SendPackage((const void *)&sInfo, sInfo.m_wLength);
  198. }
  199. break;
  200. case enumC2S_TONG_GET_MEMBER_INFO:
  201. {
  202. STONG_GET_MEMBER_INFO_COMMAND *pGet = (STONG_GET_MEMBER_INFO_COMMAND*)pData;
  203. STONG_MEMBER_INFO_SYNC sInfo;
  204. if (g_cTongSet.GetTongMemberInfo(pGet, &sInfo))
  205. this->SendPackage((const void *)&sInfo, sInfo.m_wLength);
  206. }
  207. break;
  208. case enumC2S_TONG_INSTATE:
  209. {
  210. STONG_INSTATE_COMMAND *pInstate = (STONG_INSTATE_COMMAND*)pData;
  211. STONG_INSTATE_SYNC sSync;
  212. sSync.ProtocolID = 0;
  213. g_cTongSet.Instate(pInstate, &sSync);
  214. if (sSync.ProtocolID != 0)
  215. this->SendPackage((const void *)&sSync, sizeof(sSync));
  216. }
  217. break;
  218. case enumC2S_TONG_KICK:
  219. {
  220. STONG_KICK_COMMAND *pKick = (STONG_KICK_COMMAND*)pData;
  221. STONG_KICK_SYNC sKick;
  222. sKick.ProtocolID = 0;
  223. g_cTongSet.Kick(pKick, &sKick);
  224. if (sKick.ProtocolID != 0)
  225. this->SendPackage((const void *)&sKick, sizeof(sKick));
  226. }
  227. break;
  228. case enumC2S_TONG_LEAVE:
  229. {
  230. STONG_LEAVE_COMMAND *pLeave = (STONG_LEAVE_COMMAND*)pData;
  231. STONG_LEAVE_SYNC sLeave;
  232. sLeave.ProtocolID = 0;
  233. g_cTongSet.Leave(pLeave, &sLeave);
  234. if (sLeave.ProtocolID != 0)
  235. this->SendPackage((const void *)&sLeave, sizeof(sLeave));
  236. }
  237. break;
  238. case enumC2S_TONG_CHANGE_MASTER:
  239. {
  240. STONG_CHANGE_MASTER_COMMAND *pChange = (STONG_CHANGE_MASTER_COMMAND*)pData;
  241. char szName[32];
  242. STONG_ONE_LEADER_INFO sInfo;
  243. memcpy(szName, pChange->m_szName, sizeof(pChange->m_szName));
  244. szName[31] = 0;
  245. if (!g_cTongSet.SearchOne(pChange->m_dwTongNameID, szName, &sInfo))
  246. {
  247. STONG_CHANGE_MASTER_FAIL_SYNC sFail;
  248. sFail.ProtocolFamily = pf_tong;
  249. sFail.ProtocolID = enumS2C_TONG_CHANGE_MASTER_FAIL;
  250. sFail.m_dwParam = pChange->m_dwParam;
  251. sFail.m_btFailID = 2;
  252. sFail.m_dwTongNameID = pChange->m_dwTongNameID;
  253. memcpy(sFail.m_szName, szName, sizeof(szName));
  254. this->SendPackage((const void *)&sFail, sizeof(sFail));
  255. break;
  256. }
  257. {{
  258. CNetConnectDup conndup;
  259. DWORD nameid = 0;
  260. unsigned long param = 0;
  261. if (g_HostServer.FindPlayerByRole(NULL, std::_tstring(szName), &conndup, NULL, &nameid, &param))
  262. {
  263. CNetConnectDup tongconndup = g_TongServer.FindTongConnectByIP(conndup.GetIP());
  264. if (tongconndup.IsValid())
  265. {
  266. STONG_CHECK_GET_MASTER_POWER_SYNC sCheck;
  267. sCheck.ProtocolFamily = pf_tong;
  268. sCheck.ProtocolID = enumS2C_TONG_CHECK_CHANGE_MASTER_POWER;
  269. sCheck.m_dwTongNameID = pChange->m_dwTongNameID;
  270. sCheck.m_btFigure = pChange->m_btFigure;
  271. sCheck.m_btPos = pChange->m_btPos;
  272. sCheck.m_dwParam = param;
  273. memcpy(sCheck.m_szName, szName, sizeof(szName));
  274. tongconndup.SendPackage((const void *)&sCheck, sizeof(sCheck));
  275. }
  276. break;
  277. }
  278. // 不在线 not find 或者 tong is not connect 当作不在线
  279. STONG_CHANGE_MASTER_FAIL_SYNC sFail;
  280. sFail.ProtocolFamily = pf_tong;
  281. sFail.ProtocolID = enumS2C_TONG_CHANGE_MASTER_FAIL;
  282. sFail.m_dwParam = pChange->m_dwParam;
  283. sFail.m_btFailID = 0;
  284. sFail.m_dwTongNameID = pChange->m_dwTongNameID;
  285. memcpy(sFail.m_szName, szName, sizeof(szName));
  286. this->SendPackage((const void *)&sFail, sizeof(sFail));
  287. }}
  288. }
  289. break;
  290. case enumC2S_TONG_ACCEPT_MASTER:
  291. {
  292. STONG_ACCEPT_MASTER_COMMAND *pAccept = (STONG_ACCEPT_MASTER_COMMAND*)pData;
  293. g_cTongSet.AcceptMaster(pAccept);
  294. }
  295. break;
  296. case enumC2S_TONG_GET_LOGIN_DATA:
  297. {
  298. STONG_GET_LOGIN_DATA_COMMAND *pLogin = (STONG_GET_LOGIN_DATA_COMMAND*)pData;
  299. STONG_LOGIN_DATA_SYNC sLogin;
  300. sLogin.m_dwParam = 0;
  301. g_cTongSet.GetLoginData(pLogin, &sLogin);
  302. if (sLogin.m_dwParam)
  303. this->SendPackage((const void *)&sLogin, sizeof(sLogin));
  304. }
  305. break;
  306. default:
  307. break;
  308. }
  309. }
  310. void CTongConnect::Proc0_Friend(const void* pData, size_t size)
  311. {
  312. EXTEND_HEADER* pHeader = (EXTEND_HEADER*)pData;
  313. if (pHeader->ProtocolID == friend_c2c_askaddfriend)
  314. {
  315. Proc1_Friend_AskAddFriend(pData, size);
  316. }
  317. else if (pHeader->ProtocolID == friend_c2c_repaddfriend)
  318. {
  319. Proc1_Friend_RepAddFriend(pData, size);
  320. }
  321. else if (pHeader->ProtocolID == friend_c2s_groupfriend)
  322. {
  323. Proc1_Friend_GroupFriend(pData, size);
  324. }
  325. else if (pHeader->ProtocolID == friend_c2s_erasefriend)
  326. {
  327. Proc1_Friend_EraseFriend(pData, size);
  328. }
  329. else if (pHeader->ProtocolID == friend_c2s_asksyncfriendlist)
  330. {
  331. Proc1_Friend_AskSyncFriendList(pData, size);
  332. }
  333. else if (pHeader->ProtocolID == friend_c2s_associate)
  334. {
  335. Proc1_Friend_Associate(pData, size);
  336. }
  337. else if (pHeader->ProtocolID == friend_c2s_associatebevy)
  338. {
  339. Proc1_Friend_AssociateBevy(pData, size);
  340. }
  341. }
  342. void CTongConnect::Proc1_Friend_AskAddFriend(const void* pData, size_t size)
  343. {
  344. ASK_ADDFRIEND_CMD* pAafCmd = (ASK_ADDFRIEND_CMD*)pData;
  345. tagPlusSrcInfo* pSrcInfo = (tagPlusSrcInfo*)((BYTE*)pData + size) - 1;
  346. if (!gIsLegalString(pAafCmd->dstrole, 1, _NAME_LEN))
  347. return;
  348. std::_tstring srcrole;
  349. if (!g_HostServer.FindPlayerByIpParam(NULL, GetIP(), pSrcInfo->lnID, NULL, NULL, &srcrole, NULL))
  350. return;
  351. std::_tstring dstrole(pAafCmd->dstrole);
  352. if (_tstring_equal()(srcrole, dstrole))
  353. return;
  354. BOOL pass = FALSE;
  355. BOOL promise = FALSE;
  356. CNetConnectDup dsthostconndup;
  357. DWORD dstnameid = 0;
  358. unsigned long dstparam = 0;
  359. if (g_HostServer.FindPlayerByRole(NULL, dstrole, &dsthostconndup, NULL, &dstnameid, &dstparam))
  360. {
  361. if (g_FriendMgr.PlayerIsFriend(dstrole, srcrole))
  362. {
  363. g_FriendMgr.PlayerAddFriend(srcrole, dstrole);
  364. promise = TRUE; //默许
  365. }
  366. else
  367. {
  368. if (g_FriendMgr.TrackAddFriend(srcrole, dstrole, pAafCmd->pckgid))
  369. {
  370. ASK_ADDFRIEND_SYNC AafSync;
  371. AafSync.ProtocolFamily = pf_friend;
  372. AafSync.ProtocolID = friend_c2c_askaddfriend;
  373. AafSync.pckgid = pAafCmd->pckgid;
  374. strcpy(AafSync.srcrole, srcrole.c_str());
  375. if (PassToSomeone(dsthostconndup.GetIP(), dstparam, dstnameid, &AafSync, sizeof(ASK_ADDFRIEND_SYNC)))
  376. pass = TRUE;
  377. else
  378. g_FriendMgr.ExtractAddFriend(srcrole, dstrole, pAafCmd->pckgid);
  379. }
  380. }
  381. }
  382. if (!pass)
  383. {
  384. REP_ADDFRIEND_SYNC RafSync;
  385. RafSync.ProtocolFamily = pf_friend;
  386. RafSync.ProtocolID = friend_c2c_repaddfriend;
  387. RafSync.pckgid = pAafCmd->pckgid;
  388. strcpy(RafSync.srcrole, pAafCmd->dstrole);
  389. RafSync.answer = promise ? answerAgree : answerUnable;
  390. PassToSomeone(GetIP(), pSrcInfo->lnID, pSrcInfo->nameid, &RafSync, sizeof(REP_ADDFRIEND_SYNC));
  391. }
  392. }
  393. void CTongConnect::Proc1_Friend_RepAddFriend(const void* pData, size_t size)
  394. {
  395. REP_ADDFRIEND_CMD* pRafCmd = (REP_ADDFRIEND_CMD*)pData;
  396. tagPlusSrcInfo* pSrcInfo = (tagPlusSrcInfo*)((BYTE*)pData + size) - 1;
  397. if (!gIsLegalString(pRafCmd->dstrole, 1, _NAME_LEN))
  398. return;
  399. std::_tstring srcrole;
  400. if (!g_HostServer.FindPlayerByIpParam(NULL, GetIP(), pSrcInfo->lnID, NULL, NULL, &srcrole, NULL))
  401. return;
  402. std::_tstring dstrole(pRafCmd->dstrole);
  403. if (_tstring_equal()(srcrole, dstrole))
  404. return;
  405. if (!g_FriendMgr.ExtractAddFriend(dstrole, srcrole, pRafCmd->pckgid))
  406. return;
  407. if (pRafCmd->answer == answerAgree)
  408. g_FriendMgr.PlayerAddFriend(srcrole, dstrole);
  409. {{
  410. CNetConnectDup dsthostconndup;
  411. DWORD dstnameid = 0;
  412. unsigned long dstparam = 0;
  413. if (g_HostServer.FindPlayerByRole(NULL, dstrole, &dsthostconndup, NULL, &dstnameid, &dstparam))
  414. {
  415. REP_ADDFRIEND_SYNC RafSync;
  416. RafSync.ProtocolFamily = pf_friend;
  417. RafSync.ProtocolID = friend_c2c_repaddfriend;
  418. RafSync.pckgid = pRafCmd->pckgid;
  419. strcpy(RafSync.srcrole, srcrole.c_str());
  420. RafSync.answer = pRafCmd->answer;
  421. PassToSomeone(dsthostconndup.GetIP(), dstparam, dstnameid, &RafSync, sizeof(REP_ADDFRIEND_SYNC));
  422. }
  423. else
  424. {
  425. FRIEND_STATE Fs;
  426. Fs.ProtocolFamily = pf_friend;
  427. Fs.ProtocolID = friend_s2c_friendstate;
  428. Fs.state = stateOffline;
  429. PassToSomeone(GetIP(), pSrcInfo->lnID, pSrcInfo->nameid, &Fs, sizeof(FRIEND_STATE));
  430. }
  431. }}
  432. }
  433. void CTongConnect::Proc1_Friend_GroupFriend(const void* pData, size_t size)
  434. {
  435. GROUP_FRIEND* pGf = (GROUP_FRIEND*)pData;
  436. tagPlusSrcInfo* pSrcInfo = (tagPlusSrcInfo*)((BYTE*)pData + size) - 1;
  437. std::_tstring srcrole;
  438. if (!g_HostServer.FindPlayerByIpParam(NULL, GetIP(), pSrcInfo->lnID, NULL, NULL, &srcrole, NULL))
  439. return;
  440. char* pGroupTag = (char*)(pGf + 1);
  441. if (*pGroupTag != specGroup)
  442. return; //error
  443. char* pGroup = (char*)(pGroupTag + 1);
  444. on_nextgroup:
  445. if (!gIsLegalString(pGroup, 0, _GROUP_NAME_LEN))
  446. return; //error
  447. std::_tstring group(pGroup);
  448. for (char* pRoleTag = pGroup + strlen(pGroup) + 1; ; )
  449. {
  450. if (*pRoleTag == specOver)
  451. return; //success
  452. else if (*pRoleTag == specGroup)
  453. {
  454. pGroup = pRoleTag + 1;
  455. goto on_nextgroup; //next group
  456. }
  457. else if (*pRoleTag == specRole)
  458. {
  459. char* pRole = pRoleTag + 1;
  460. if (!gIsLegalString(pRole, 1, _NAME_LEN))
  461. return; //error
  462. std::_tstring role(pRole);
  463. g_FriendMgr.SetFriendGroup(srcrole, role, group);
  464. pRoleTag = pRole + role.size() + 1;
  465. continue;  //next role
  466. }
  467. else
  468. return; //error
  469. }
  470. }
  471. void CTongConnect::Proc1_Friend_EraseFriend(const void* pData, size_t size)
  472. {
  473. ERASE_FRIEND* pEf = (ERASE_FRIEND*)pData;
  474. tagPlusSrcInfo* pSrcInfo = (tagPlusSrcInfo*)((BYTE*)pData + size) - 1;
  475. if (!gIsLegalString(pEf->friendrole, 1, _NAME_LEN))
  476. return;
  477. std::_tstring srcrole;
  478. if (!g_HostServer.FindPlayerByIpParam(NULL, GetIP(), pSrcInfo->lnID, NULL, NULL, &srcrole, NULL))
  479. return;
  480. g_FriendMgr.PlayerDelFriend(srcrole, std::_tstring(pEf->friendrole));
  481. }
  482. void CTongConnect::Proc1_Friend_AskSyncFriendList(const void* pData, size_t size)
  483. {
  484. ASK_SYNCFRIENDLIST* pAsfl = (ASK_SYNCFRIENDLIST*)pData;
  485. tagPlusSrcInfo* pSrcInfo = (tagPlusSrcInfo*)((BYTE*)pData + size) - 1;
  486. std::_tstring role;
  487. if (!g_HostServer.FindPlayerByIpParam(NULL, GetIP(), pSrcInfo->lnID, NULL, NULL, &role, NULL))
  488. return;
  489. g_FriendMgr.SomeoneSyncFriends(role, pSrcInfo->lnID, pSrcInfo->nameid, CNetConnectDup(*this), pAsfl->full, pAsfl->pckgid);
  490. }
  491. void CTongConnect::Proc1_Friend_Associate(const void* pData, size_t size)
  492. {
  493. FRIEND_ASSOCIATE* pFa = (FRIEND_ASSOCIATE*)pData;
  494. char* szGroup = (char*)(pFa + 1);
  495. if (!gIsLegalString(szGroup, 0, _GROUP_NAME_LEN))
  496. return;
  497. std::_tstring group(szGroup);
  498. char* szRole1 = szGroup + group.size() + 1;
  499. if (!gIsLegalString(szRole1, 1, _NAME_LEN))
  500. return;
  501. std::_tstring role1(szRole1);
  502. char* szRole2 = szRole1 + role1.size() + 1;
  503. if (!gIsLegalString(szRole2, 1, _NAME_LEN))
  504. return;
  505. std::_tstring role2(szRole2);
  506. if (_tstring_equal()(role1, role2))
  507. return;
  508. {{
  509. g_FriendMgr.PlayerAssociate(role1, role2, group, pFa->bidir);
  510. }}
  511. size_t basesize = sizeof(FRIEND_SYNCASSOCIATE) + group.size() + 1;
  512. size_t role1size = role1.size() + 1;
  513. size_t role2size = role2.size() + 1;
  514. size_t maxsize = basesize + (pFa->bidir ? max(role1size, role2size) : role2size) + 1;
  515. FRIEND_SYNCASSOCIATE* pFsa = (FRIEND_SYNCASSOCIATE*)_alloca(maxsize);
  516. pFsa->ProtocolFamily = pf_friend;
  517. pFsa->ProtocolID = friend_s2c_syncassociate;
  518. char* szGroupSync = (char*)(pFsa + 1);
  519. strcpy(szGroupSync, group.c_str());
  520. char* szRoleSync = szGroupSync + group.size() + 1;
  521. {{
  522. CNetConnectDup conndup;
  523. DWORD nameid = 0;
  524. unsigned long param = 0;
  525. if (g_HostServer.FindPlayerByRole(NULL, role1, &conndup, NULL, &nameid, &param))
  526. {
  527. size_t pckgsize = basesize + role2size + 1;
  528. strcpy(szRoleSync, role2.c_str());
  529. szRoleSync[role2size] = 0;
  530. PassToSomeone(conndup.GetIP(), param, nameid, pFsa, pckgsize);
  531. }
  532. }}
  533. if (pFa->bidir)
  534. {
  535. CNetConnectDup conndup2;
  536. DWORD nameid2 = 0;
  537. unsigned long param2 = 0;
  538. if (g_HostServer.FindPlayerByRole(NULL, role2, &conndup2, NULL, &nameid2, &param2))
  539. {
  540. size_t pckgsize2 = basesize + role1size + 1;
  541. strcpy(szRoleSync, role1.c_str());
  542. szRoleSync[role1size] = 0;
  543. PassToSomeone(conndup2.GetIP(), param2, nameid2, pFsa, pckgsize2);
  544. }
  545. }
  546. }
  547. void CTongConnect::Proc1_Friend_AssociateBevy(const void* pData, size_t size)
  548. {
  549. FRIEND_ASSOCIATEBEVY* pFab = (FRIEND_ASSOCIATEBEVY*)pData;
  550. std::_tstring group;
  551. CFriendMgr::_BEVY bevy;
  552. size_t rolessize = 0;
  553. {{
  554. char* szGroup = (char*)(pFab + 1);
  555. if (!gIsLegalString(szGroup, 0, _GROUP_NAME_LEN))
  556. return;
  557. group.assign(szGroup);
  558. char* szRoles = szGroup + group.size() + 1;
  559. while (*szRoles)
  560. {
  561. if (!gIsLegalString(szRoles, 1, _NAME_LEN))
  562. return;
  563. std::_tstring role(szRoles);
  564. bevy.push_back(role);
  565. szRoles += role.size() + 1;
  566. rolessize += role.size() + 1;
  567. }
  568. if (bevy.size() < 2)
  569. return;
  570. }}
  571. g_FriendMgr.PlayerAssociateBevy(bevy, group);
  572. {{
  573. size_t basesize = sizeof(FRIEND_SYNCASSOCIATE) + group.size() + 1;
  574. size_t maxsize = basesize + rolessize + 1;
  575. FRIEND_SYNCASSOCIATE* pFsa = (FRIEND_SYNCASSOCIATE*)_alloca(maxsize);
  576. pFsa->ProtocolFamily = pf_friend;
  577. pFsa->ProtocolID = friend_s2c_syncassociate;
  578. char* szGroupSync = (char*)(pFsa + 1);
  579. strcpy(szGroupSync, group.c_str());
  580. char* szRolesSync = szGroupSync + group.size() + 1;
  581. for (CFriendMgr::_BEVY::iterator itS = bevy.begin(); itS != bevy.end(); itS++)
  582. {
  583. std::_tstring someone = *itS;
  584. CNetConnectDup conndup;
  585. DWORD nameid = 0;
  586. unsigned long param = 0;
  587. if (!g_HostServer.FindPlayerByRole(NULL, someone, &conndup, NULL, &nameid, &param))
  588. continue;
  589. size_t cursor = 0;
  590. for (CFriendMgr::_BEVY::iterator itD = bevy.begin(); itD != bevy.end(); itD++)
  591. {
  592. if (itD == itS)
  593. continue;
  594. std::_tstring dst = *itD;
  595. strcpy(szRolesSync + cursor, dst.c_str());
  596. cursor += dst.size() + 1;
  597. }
  598. szRolesSync[cursor++] = 0;
  599. PassToSomeone(conndup.GetIP(), param, nameid, pFsa, basesize + cursor);
  600. }
  601. }}
  602. }