KTongControl.cpp
Upload User: dzyhzl
Upload Date: 2019-04-29
Package Size: 56270k
Code Size: 36k
Development Platform:

C/C++

  1. // KTongControl.cpp: implementation of the CTongControl class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "Global.h"
  6. #include "KTongControl.h"
  7. #define defTONG_INIT_MEMBER_SIZE 100 // 成员内存初始化时的大小
  8. #define defTONG_MEMBER_SIZE_ADD 100 // 成员内存每次增加的大小
  9. //////////////////////////////////////////////////////////////////////
  10. // Construction/Destruction
  11. //////////////////////////////////////////////////////////////////////
  12. CTongControl::CTongControl(int nCamp, char *lpszPlayerName, char *lpszTongName)
  13. {
  14. m_nCamp = 0;
  15. m_dwMoney = 0;
  16. m_nCredit = 0;
  17. m_nLevel = 0;
  18. m_nDirectorNum = 0;
  19. m_nManagerNum = 0;
  20. m_nMemberNum = 0;
  21. m_dwNameID = 0;
  22. m_szName[0] = 0;
  23. m_szPassword[0] = 0;
  24. m_szMasterTitle[0] = 0;
  25. memset(m_szDirectorTitle, 0, sizeof(m_szDirectorTitle));
  26. memset(m_szManagerTitle, 0, sizeof(m_szManagerTitle));
  27. m_szNormalTitle[0] = 0;
  28. m_dwMasterID = 0;
  29. m_szMasterName[0] = 0;
  30. memset(m_dwDirectorID, 0, sizeof(m_dwDirectorID));
  31. memset(m_szDirectorName, 0, sizeof(m_szDirectorName));
  32. memset(m_dwManagerID, 0, sizeof(m_dwManagerID));
  33. memset(m_szManagerName, 0, sizeof(m_szManagerName));
  34. m_psMember = (STONG_MEMBER*)new STONG_MEMBER[defTONG_INIT_MEMBER_SIZE];
  35. m_nMemberPointSize = defTONG_INIT_MEMBER_SIZE;
  36. memset(m_psMember, 0, sizeof(STONG_MEMBER) * m_nMemberPointSize);
  37. if (nCamp != camp_justice && nCamp != camp_evil && nCamp != camp_balance)
  38. return;
  39. if (!lpszPlayerName || !lpszPlayerName[0] || strlen(lpszPlayerName) >= defTONG_STR_LENGTH)
  40. return;
  41. if (!lpszTongName || !lpszTongName[0] || strlen(lpszTongName) >= defTONG_STR_LENGTH)
  42. return;
  43. m_nCamp = nCamp;
  44. strcpy(m_szMasterName, lpszPlayerName);
  45. m_dwMasterID = g_String2Id(m_szMasterName);
  46. strcpy(m_szName, lpszTongName);
  47. m_dwNameID = g_String2Id(m_szName);
  48. }
  49. CTongControl::CTongControl(TTongList sList)
  50. {
  51. m_nCamp = 0;
  52. m_dwMoney = 0;
  53. m_nCredit = 0;
  54. m_nLevel = 0;
  55. m_nDirectorNum = 0;
  56. m_nManagerNum = 0;
  57. strcpy(m_szName, sList.szName);
  58. m_dwNameID = g_String2Id(m_szName);
  59. m_szPassword[0] = 0;
  60. m_szMasterTitle[0] = 0;
  61. memset(m_szDirectorTitle, 0, sizeof(m_szDirectorTitle));
  62. memset(m_szManagerTitle, 0, sizeof(m_szManagerTitle));
  63. m_szNormalTitle[0] = 0;
  64. m_dwMasterID = 0;
  65. m_szMasterName[0] = 0;
  66. memset(m_dwDirectorID, 0, sizeof(m_dwDirectorID));
  67. memset(m_szDirectorName, 0, sizeof(m_szDirectorName));
  68. memset(m_dwManagerID, 0, sizeof(m_dwManagerID));
  69. memset(m_szManagerName, 0, sizeof(m_szManagerName));
  70. m_nMemberNum = sList.MemberCount;
  71. m_nMemberPointSize = m_nMemberNum + defTONG_INIT_MEMBER_SIZE;
  72. m_psMember = (STONG_MEMBER*)new STONG_MEMBER[m_nMemberPointSize];
  73. memset(m_psMember, 0, sizeof(STONG_MEMBER) * m_nMemberPointSize);
  74. }
  75. CTongControl::~CTongControl()
  76. {
  77. if (m_psMember)
  78. delete []m_psMember;
  79. }
  80. BOOL CTongControl::AddMember(char *lpszPlayerName)
  81. {
  82. // 这种情况不应该发生
  83. if (m_nMemberPointSize <= 0 || !m_psMember)
  84. return FALSE;
  85. if (!lpszPlayerName || strlen(lpszPlayerName) >= defTONG_STR_LENGTH)
  86. return FALSE;
  87. // 寻找空位
  88. for (int i = 0; i < m_nMemberPointSize; i++)
  89. {
  90. if (m_psMember[i].m_dwNameID == 0)
  91. break;
  92. }
  93. // 没找着,满了,开辟一块更大的内存
  94. if (i >= m_nMemberPointSize)
  95. {
  96. i = m_nMemberPointSize;
  97. // 暂时备份一下
  98. STONG_MEMBER *pTemp;
  99. pTemp = (STONG_MEMBER*)new STONG_MEMBER[m_nMemberPointSize];
  100. memcpy(pTemp, m_psMember, sizeof(STONG_MEMBER) * m_nMemberPointSize);
  101. // 分配更大的内存
  102. delete []m_psMember;
  103. m_psMember = (STONG_MEMBER*)new STONG_MEMBER[m_nMemberPointSize + defTONG_MEMBER_SIZE_ADD];
  104. memcpy(m_psMember, pTemp, sizeof(STONG_MEMBER) * m_nMemberPointSize);
  105. memset(&m_psMember[m_nMemberPointSize], 0, sizeof(STONG_MEMBER) * defTONG_MEMBER_SIZE_ADD);
  106. m_nMemberPointSize += defTONG_MEMBER_SIZE_ADD;
  107. delete []pTemp;
  108. }
  109. // 增加一个成员
  110. strcpy(m_psMember[i].m_szName, lpszPlayerName);
  111. m_psMember[i].m_dwNameID = g_String2Id(lpszPlayerName);
  112. m_nMemberNum++;
  113. return TRUE;
  114. }
  115. BOOL CTongControl::ChangePassword(char *lpOld, char *lpNew)
  116. {
  117. if (!lpOld || !lpNew)
  118. return FALSE;
  119. if (strlen(lpNew) >= defTONG_STR_LENGTH || strcmp(lpOld, m_szPassword) != 0)
  120. return FALSE;
  121. strcpy(m_szPassword, lpNew);
  122. return TRUE;
  123. }
  124. BOOL CTongControl::GetTongHeadInfo(STONG_HEAD_INFO_SYNC *pInfo)
  125. {
  126. if (!pInfo)
  127. return FALSE;
  128. int i, j;
  129. pInfo->ProtocolFamily = pf_tong;
  130. pInfo->ProtocolID = enumS2C_TONG_HEAD_INFO;
  131. pInfo->m_dwMoney = m_dwMoney;
  132. pInfo->m_nCredit = m_nCredit;
  133. pInfo->m_btCamp = m_nCamp;
  134. pInfo->m_btLevel = m_nLevel;
  135. pInfo->m_btManagerNum = m_nManagerNum;
  136. pInfo->m_dwMemberNum = m_nMemberNum;
  137. strcpy(pInfo->m_szTongName, m_szName);
  138. pInfo->m_sMember[0].m_btFigure = enumTONG_FIGURE_MASTER;
  139. pInfo->m_sMember[0].m_btPos = 0;
  140. strcpy(pInfo->m_sMember[0].m_szTitle, this->m_szMasterTitle);
  141. strcpy(pInfo->m_sMember[0].m_szName, this->m_szMasterName);
  142. pInfo->m_btDirectorNum = 0;
  143. for (i = 0, j = 1; i < defTONG_MAX_DIRECTOR; i++)
  144. {
  145. if (!m_szDirectorName[i][0])
  146. continue;
  147. pInfo->m_sMember[j].m_btFigure = enumTONG_FIGURE_DIRECTOR;
  148. pInfo->m_sMember[j].m_btPos = i;
  149. strcpy(pInfo->m_sMember[j].m_szTitle, this->m_szDirectorTitle[i]);
  150. strcpy(pInfo->m_sMember[j].m_szName, this->m_szDirectorName[i]);
  151. j++;
  152. pInfo->m_btDirectorNum++;
  153. }
  154. pInfo->m_wLength = sizeof(STONG_HEAD_INFO_SYNC) - sizeof(pInfo->m_sMember) + sizeof(STONG_ONE_LEADER_INFO) * (1 + pInfo->m_btDirectorNum);
  155. return TRUE;
  156. }
  157. BOOL CTongControl::GetTongManagerInfo(
  158. STONG_GET_MANAGER_INFO_COMMAND *pApply,
  159. STONG_MANAGER_INFO_SYNC *pInfo)
  160. {
  161. if (!pApply || !pInfo)
  162. return FALSE;
  163. if (pApply->m_nParam3 <= 0)
  164. return FALSE;
  165. pInfo->ProtocolFamily = pf_tong;
  166. pInfo->ProtocolID = enumS2C_TONG_MANAGER_INFO;
  167. pInfo->m_dwParam = pApply->m_dwParam;
  168. pInfo->m_dwMoney = m_dwMoney;
  169. pInfo->m_nCredit = m_nCredit;
  170. pInfo->m_btCamp = m_nCamp;
  171. pInfo->m_btLevel = m_nLevel;
  172. pInfo->m_btDirectorNum = m_nDirectorNum;
  173. pInfo->m_btManagerNum = m_nManagerNum;
  174. pInfo->m_dwMemberNum = m_nMemberNum;
  175. pInfo->m_btStartNo = pApply->m_nParam2;
  176. strcpy(pInfo->m_szTongName, m_szName);
  177. int nNeedNum, nStartNum, i, j;
  178. nStartNum = pApply->m_nParam2;
  179. nNeedNum = pApply->m_nParam3;
  180. if (nNeedNum > defTONG_ONE_PAGE_MAX_NUM)
  181. nNeedNum = defTONG_ONE_PAGE_MAX_NUM;
  182. pInfo->m_btCurNum = 0;
  183. // 找开始位置
  184. for (i = 0, j = 0; i < defTONG_MAX_MANAGER; i++)
  185. {
  186. if (j >= nStartNum)
  187. break;
  188. if (m_szManagerName[i][0])
  189. j++;
  190. }
  191. if (i >= defTONG_MAX_MANAGER || j < nStartNum)
  192. return FALSE;
  193. // 开始记录数据
  194. for (; i < defTONG_MAX_MANAGER; i++)
  195. {
  196. if (pInfo->m_btCurNum >= nNeedNum)
  197. break;
  198. if (!m_szManagerName[i][0])
  199. continue;
  200. pInfo->m_sMember[pInfo->m_btCurNum].m_btFigure = enumTONG_FIGURE_MANAGER;
  201. pInfo->m_sMember[pInfo->m_btCurNum].m_btPos = i;
  202. strcpy(pInfo->m_sMember[pInfo->m_btCurNum].m_szTitle, m_szManagerTitle[i]);
  203. strcpy(pInfo->m_sMember[pInfo->m_btCurNum].m_szName, m_szManagerName[i]);
  204. pInfo->m_btCurNum++;
  205. }
  206. if (pInfo->m_btCurNum == 0)
  207. return FALSE;
  208. pInfo->m_wLength = sizeof(STONG_MANAGER_INFO_SYNC) - sizeof(STONG_ONE_LEADER_INFO) * (defTONG_ONE_PAGE_MAX_NUM - pInfo->m_btCurNum);
  209. return TRUE;
  210. }
  211. BOOL CTongControl::GetTongMemberInfo(
  212. STONG_GET_MEMBER_INFO_COMMAND *pApply,
  213. STONG_MEMBER_INFO_SYNC *pInfo)
  214. {
  215. if (!pApply || !pInfo)
  216. return FALSE;
  217. if (pApply->m_nParam3 <= 0)
  218. return FALSE;
  219. if (!m_psMember || m_nMemberPointSize <= 0)
  220. return FALSE;
  221. pInfo->ProtocolFamily = pf_tong;
  222. pInfo->ProtocolID = enumS2C_TONG_MEMBER_INFO;
  223. pInfo->m_dwParam = pApply->m_dwParam;
  224. pInfo->m_dwMoney = m_dwMoney;
  225. pInfo->m_nCredit = m_nCredit;
  226. pInfo->m_btCamp = m_nCamp;
  227. pInfo->m_btLevel = m_nLevel;
  228. pInfo->m_btDirectorNum = m_nDirectorNum;
  229. pInfo->m_btManagerNum = m_nManagerNum;
  230. pInfo->m_dwMemberNum = m_nMemberNum;
  231. pInfo->m_btStartNo = pApply->m_nParam2;
  232. strcpy(pInfo->m_szTitle, m_szNormalTitle);
  233. strcpy(pInfo->m_szTongName, m_szName);
  234. int nNeedNum, nStartNum, i, j;
  235. nStartNum = pApply->m_nParam2;
  236. nNeedNum = pApply->m_nParam3;
  237. if (nNeedNum > defTONG_ONE_PAGE_MAX_NUM)
  238. nNeedNum = defTONG_ONE_PAGE_MAX_NUM;
  239. pInfo->m_btCurNum = 0;
  240. // 找开始位置
  241. for (i = 0, j = 0; i < m_nMemberPointSize; i++)
  242. {
  243. if (j >= nStartNum)
  244. break;
  245. if (m_psMember[i].m_szName[0])
  246. j++;
  247. }
  248. if (i >= m_nMemberPointSize || j < nStartNum)
  249. return FALSE;
  250. // 开始记录数据
  251. for (; i < m_nMemberPointSize; i++)
  252. {
  253. if (pInfo->m_btCurNum >= nNeedNum)
  254. break;
  255. if (!m_psMember[i].m_szName[0])
  256. continue;
  257. strcpy(pInfo->m_sMember[pInfo->m_btCurNum].m_szName, m_psMember[i].m_szName);
  258. pInfo->m_btCurNum++;
  259. }
  260. if (pInfo->m_btCurNum == 0)
  261. return FALSE;
  262. pInfo->m_wLength = sizeof(STONG_MEMBER_INFO_SYNC) - sizeof(STONG_ONE_MEMBER_INFO) * (defTONG_ONE_PAGE_MAX_NUM - pInfo->m_btCurNum);
  263. return TRUE;
  264. }
  265. BOOL CTongControl::Instate(STONG_INSTATE_COMMAND *pInstate, STONG_INSTATE_SYNC *pSync)
  266. {
  267. if (!pInstate || !pSync)
  268. return FALSE;
  269. if (pInstate->m_btCurFigure == pInstate->m_btNewFigure && pInstate->m_btCurPos == pInstate->m_btNewPos)
  270. return FALSE;
  271. int i, nOldPos, nNewPos;
  272. DWORD dwNameID;
  273. char szName[32];
  274. memcpy(szName, pInstate->m_szName, sizeof(pInstate->m_szName));
  275. szName[31] = 0;
  276. dwNameID = g_String2Id(szName);
  277. if (dwNameID == 0)
  278. return FALSE;
  279. pSync->ProtocolFamily = pf_tong;
  280. pSync->ProtocolID = enumS2C_TONG_INSTATE;
  281. pSync->m_btOldFigure = pInstate->m_btCurFigure;
  282. pSync->m_btOldPos = 0;
  283. pSync->m_btNewFigure = pInstate->m_btNewFigure;
  284. pSync->m_btNewPos = 0;
  285. pSync->m_dwParam = pInstate->m_dwParam;
  286. pSync->m_btSuccessFlag = 0;
  287. pSync->m_dwTongNameID = pInstate->m_dwTongNameID;
  288. pSync->m_szTitle[0] = 0;
  289. strcpy(pSync->m_szName, szName);
  290. if (pInstate->m_btCurFigure == enumTONG_FIGURE_DIRECTOR)
  291. {
  292. for (i = 0; i < defTONG_MAX_DIRECTOR; i++)
  293. {
  294. if (m_dwDirectorID[i] == dwNameID && strcmp(szName, m_szDirectorName[i]) == 0)
  295. break;
  296. }
  297. if (i >= defTONG_MAX_DIRECTOR)
  298. return FALSE;
  299. nOldPos = i;
  300. switch (pInstate->m_btNewFigure)
  301. {
  302. case enumTONG_FIGURE_MANAGER:
  303. for (i = 0; i < defTONG_MAX_MANAGER; i++)
  304. {
  305. if (m_dwManagerID[i] == 0 && !m_szManagerName[i][0])
  306. break;
  307. }
  308. if (i >= defTONG_MAX_MANAGER)
  309. return FALSE;
  310. nNewPos = i;
  311. strcpy(m_szManagerName[nNewPos], szName);
  312. m_dwManagerID[nNewPos] = dwNameID;
  313. m_szDirectorName[nOldPos][0] = 0;
  314. m_dwDirectorID[nOldPos] = 0;
  315. m_nDirectorNum--;
  316. m_nManagerNum++;
  317. strcpy(pSync->m_szTitle, m_szManagerTitle[nNewPos]);
  318. break;
  319. case enumTONG_FIGURE_MEMBER:
  320. if (!AddMember(szName))
  321. return FALSE;
  322. m_szDirectorName[nOldPos][0] = 0;
  323. m_dwDirectorID[nOldPos] = 0;
  324. m_nDirectorNum--;
  325. strcpy(pSync->m_szTitle, m_szNormalTitle);
  326. break;
  327. default:
  328. return FALSE;
  329. }
  330. }
  331. else if (pInstate->m_btCurFigure == enumTONG_FIGURE_MANAGER)
  332. {
  333. for (i = 0; i < defTONG_MAX_MANAGER; i++)
  334. {
  335. if (m_dwManagerID[i] == dwNameID && strcmp(szName, m_szManagerName[i]) == 0)
  336. break;
  337. }
  338. if (i >= defTONG_MAX_MANAGER)
  339. return FALSE;
  340. nOldPos = i;
  341. switch (pInstate->m_btNewFigure)
  342. {
  343. case enumTONG_FIGURE_DIRECTOR:
  344. for (i = 0; i < defTONG_MAX_DIRECTOR; i++)
  345. {
  346. if (m_dwDirectorID[i] == 0 && !m_szDirectorName[i][0])
  347. break;
  348. }
  349. if (i >= defTONG_MAX_DIRECTOR)
  350. return FALSE;
  351. nNewPos = i;
  352. strcpy(m_szDirectorName[nNewPos], szName);
  353. m_dwDirectorID[nNewPos] = dwNameID;
  354. m_szManagerName[nOldPos][0] = 0;
  355. m_dwManagerID[nOldPos] = 0;
  356. m_nDirectorNum++;
  357. m_nManagerNum--;
  358. strcpy(pSync->m_szTitle, m_szDirectorTitle[nNewPos]);
  359. break;
  360. case enumTONG_FIGURE_MEMBER:
  361. if (!AddMember(szName))
  362. return FALSE;
  363. m_szManagerName[nOldPos][0] = 0;
  364. m_dwManagerID[nOldPos] = 0;
  365. m_nManagerNum--;
  366. strcpy(pSync->m_szTitle, m_szNormalTitle);
  367. break;
  368. default:
  369. return FALSE;
  370. }
  371. }
  372. else if (pInstate->m_btCurFigure == enumTONG_FIGURE_MEMBER)
  373. {
  374. if (!m_psMember)
  375. return FALSE;
  376. int nPos = -1;
  377. for (int i = 0; i < m_nMemberPointSize; i++)
  378. {
  379. if (m_psMember[i].m_dwNameID != dwNameID)
  380. continue;
  381. nPos = i;
  382. break;
  383. }
  384. if (nPos < 0)
  385. return FALSE;
  386. nOldPos = 0;
  387. switch (pInstate->m_btNewFigure)
  388. {
  389. case enumTONG_FIGURE_DIRECTOR:
  390. for (i = 0; i < defTONG_MAX_DIRECTOR; i++)
  391. {
  392. if (m_dwDirectorID[i] == 0 && !m_szDirectorName[i][0])
  393. break;
  394. }
  395. if (i >= defTONG_MAX_DIRECTOR)
  396. return FALSE;
  397. nNewPos = i;
  398. strcpy(m_szDirectorName[nNewPos], szName);
  399. m_dwDirectorID[nNewPos] = dwNameID;
  400. this->m_psMember[nPos].m_szName[0] = 0;
  401. this->m_psMember[nPos].m_dwNameID = 0;
  402. m_nDirectorNum++;
  403. m_nMemberNum--;
  404. strcpy(pSync->m_szTitle, m_szDirectorTitle[nNewPos]);
  405. break;
  406. case enumTONG_FIGURE_MANAGER:
  407. for (i = 0; i < defTONG_MAX_MANAGER; i++)
  408. {
  409. if (m_dwManagerID[i] == 0 && !m_szManagerName[i][0])
  410. break;
  411. }
  412. if (i >= defTONG_MAX_MANAGER)
  413. return FALSE;
  414. nNewPos = i;
  415. strcpy(m_szManagerName[nNewPos], szName);
  416. m_dwManagerID[nNewPos] = dwNameID;
  417. this->m_psMember[nPos].m_szName[0] = 0;
  418. this->m_psMember[nPos].m_dwNameID = 0;
  419. m_nManagerNum++;
  420. m_nMemberNum--;
  421. strcpy(pSync->m_szTitle, m_szManagerTitle[nNewPos]);
  422. break;
  423. default:
  424. return FALSE;
  425. }
  426. }
  427. pSync->m_btSuccessFlag = 1;
  428. pSync->m_btOldPos = nOldPos;
  429. pSync->m_btNewPos = nNewPos;
  430. {{
  431. CNetConnectDup conndup;
  432. DWORD nameid = 0;
  433. unsigned long param = 0;
  434. if (g_HostServer.FindPlayerByRole(NULL, std::_tstring(szName), &conndup, NULL, &nameid, &param))
  435. {
  436. CNetConnectDup tongconndup = g_TongServer.FindTongConnectByIP(conndup.GetIP());
  437. if (tongconndup.IsValid())
  438. {
  439. STONG_BE_INSTATED_SYNC sSync;
  440. sSync.ProtocolFamily = pf_tong;
  441. sSync.ProtocolID = enumS2C_TONG_BE_INSTATED;
  442. sSync.m_btFigure = pInstate->m_btNewFigure;
  443. sSync.m_btPos = nNewPos;
  444. sSync.m_dwParam = param;
  445. strcpy(sSync.m_szName, szName);
  446. switch (pInstate->m_btNewFigure)
  447. {
  448. case enumTONG_FIGURE_DIRECTOR:
  449. strcpy(sSync.m_szTitle, m_szDirectorTitle[nNewPos]);
  450. break;
  451. case enumTONG_FIGURE_MANAGER:
  452. strcpy(sSync.m_szTitle, m_szManagerTitle[nNewPos]);
  453. break;
  454. case enumTONG_FIGURE_MEMBER:
  455. strcpy(sSync.m_szTitle, this->m_szNormalTitle);
  456. break;
  457. }
  458. tongconndup.SendPackage((const void *)&sSync, sizeof(sSync));
  459. }
  460. else
  461. {
  462. //tong is not connect
  463. }
  464. }
  465. else
  466. {
  467. //not find
  468. }
  469. }}
  470. // 向帮会频道发消息,某人被任命
  471. char szMsg[96];
  472. sprintf(szMsg, "\O%u", m_dwNameID);
  473. DWORD channid = g_ChannelMgr.GetChannelID(szMsg, 0);
  474. if (channid != -1)
  475. {
  476. if (pSync->m_szTitle[0])
  477. sprintf(szMsg, "%s被任命为%s!", szName, pSync->m_szTitle);
  478. else
  479. {
  480. switch (pSync->m_btNewFigure)
  481. {
  482. case enumTONG_FIGURE_DIRECTOR:
  483. sprintf(szMsg, "%s被任命为长老!", szName);
  484. break;
  485. case enumTONG_FIGURE_MANAGER:
  486. sprintf(szMsg, "%s被任命为队长!", szName);
  487. break;
  488. case enumTONG_FIGURE_MEMBER:
  489. sprintf(szMsg, "%s被任命为普通帮众!", szName);
  490. break;
  491. }
  492. }
  493. g_ChannelMgr.SayOnChannel(channid, TRUE, std::string(), std::string("公告"), std::string(szMsg));
  494. }
  495. // 存盘,数据保存至数据库
  496. TMemberStruct sMember;
  497. sMember.MemberClass = (TONG_MEMBER_FIGURE)pInstate->m_btNewFigure;
  498. sMember.nTitleIndex = nNewPos;
  499. strcpy(sMember.szTong, this->m_szName);
  500. strcpy(sMember.szName, szName);
  501. g_cTongDB.ChangeMember(sMember);
  502. return TRUE;
  503. }
  504. /*
  505. BOOL CTongControl::Instate(STONG_INSTATE_COMMAND *pInstate, STONG_INSTATE_SYNC *pSync)
  506. {
  507. if (!pInstate || !pSync)
  508. return FALSE;
  509. if (pInstate->m_btCurFigure == pInstate->m_btNewFigure && pInstate->m_btCurPos == pInstate->m_btNewPos)
  510. return FALSE;
  511. char szName[32];
  512. memcpy(szName, pInstate->m_szName, sizeof(pInstate->m_szName));
  513. szName[31] = 0;
  514. pSync->ProtocolFamily = pf_tong;
  515. pSync->ProtocolID = enumS2C_TONG_INSTATE;
  516. pSync->m_btOldFigure = pInstate->m_btCurFigure;
  517. pSync->m_btOldPos = pInstate->m_btCurPos;
  518. pSync->m_btNewFigure = pInstate->m_btNewFigure;
  519. pSync->m_btNewPos = pInstate->m_btNewPos;
  520. pSync->m_dwParam = pInstate->m_dwParam;
  521. pSync->m_btSuccessFlag = 0;
  522. pSync->m_dwTongNameID = pInstate->m_dwTongNameID;
  523. pSync->m_szTitle[0] = 0;
  524. strcpy(pSync->m_szName, szName);
  525. if (pInstate->m_btCurFigure == enumTONG_FIGURE_DIRECTOR)
  526. {
  527. if (pInstate->m_btCurPos >= defTONG_MAX_DIRECTOR)
  528. return FALSE;
  529. if (!m_szDirectorName[pInstate->m_btCurPos][0] ||
  530. strcmp(szName, m_szDirectorName[pInstate->m_btCurPos]) != 0)
  531. return FALSE;
  532. switch (pInstate->m_btNewFigure)
  533. {
  534. case enumTONG_FIGURE_DIRECTOR:
  535. if (pInstate->m_btNewPos >= defTONG_MAX_DIRECTOR)
  536. return FALSE;
  537. if (m_szDirectorName[pInstate->m_btNewPos][0])
  538. return FALSE;
  539. strcpy(m_szDirectorName[pInstate->m_btNewPos], szName);
  540. m_dwDirectorID[pInstate->m_btNewPos] = g_String2Id(szName);
  541. m_szDirectorName[pInstate->m_btCurPos][0] = 0;
  542. m_dwDirectorID[pInstate->m_btCurPos] = 0;
  543. strcpy(pSync->m_szTitle, m_szDirectorTitle[pInstate->m_btNewPos]);
  544. break;
  545. case enumTONG_FIGURE_MANAGER:
  546. if (pInstate->m_btNewPos >= defTONG_MAX_MANAGER)
  547. return FALSE;
  548. if (m_szManagerName[pInstate->m_btNewPos][0])
  549. return FALSE;
  550. strcpy(m_szManagerName[pInstate->m_btNewPos], szName);
  551. m_dwManagerID[pInstate->m_btNewPos] = g_String2Id(szName);
  552. m_szDirectorName[pInstate->m_btCurPos][0] = 0;
  553. m_dwDirectorID[pInstate->m_btCurPos] = 0;
  554. m_nDirectorNum--;
  555. m_nManagerNum++;
  556. strcpy(pSync->m_szTitle, m_szManagerTitle[pInstate->m_btNewPos]);
  557. break;
  558. case enumTONG_FIGURE_MEMBER:
  559. if (!AddMember(szName))
  560. return FALSE;
  561. m_szDirectorName[pInstate->m_btCurPos][0] = 0;
  562. m_dwDirectorID[pInstate->m_btCurPos] = 0;
  563. m_nDirectorNum--;
  564. strcpy(pSync->m_szTitle, m_szNormalTitle);
  565. break;
  566. default:
  567. return FALSE;
  568. }
  569. }
  570. else if (pInstate->m_btCurFigure == enumTONG_FIGURE_MANAGER)
  571. {
  572. if (pInstate->m_btCurPos >= defTONG_MAX_MANAGER)
  573. return FALSE;
  574. if (!m_szManagerName[pInstate->m_btCurPos][0] ||
  575. strcmp(szName, m_szManagerName[pInstate->m_btCurPos]) != 0)
  576. return FALSE;
  577. switch (pInstate->m_btNewFigure)
  578. {
  579. case enumTONG_FIGURE_DIRECTOR:
  580. if (pInstate->m_btNewPos >= defTONG_MAX_DIRECTOR)
  581. return FALSE;
  582. if (m_szDirectorName[pInstate->m_btNewPos][0])
  583. return FALSE;
  584. strcpy(m_szDirectorName[pInstate->m_btNewPos], szName);
  585. m_dwDirectorID[pInstate->m_btNewPos] = g_String2Id(szName);
  586. m_szManagerName[pInstate->m_btCurPos][0] = 0;
  587. m_dwManagerID[pInstate->m_btCurPos] = 0;
  588. m_nDirectorNum++;
  589. m_nManagerNum--;
  590. strcpy(pSync->m_szTitle, m_szDirectorTitle[pInstate->m_btNewPos]);
  591. break;
  592. case enumTONG_FIGURE_MANAGER:
  593. if (pInstate->m_btNewPos >= defTONG_MAX_MANAGER)
  594. return FALSE;
  595. if (m_szManagerName[pInstate->m_btNewPos][0])
  596. return FALSE;
  597. strcpy(m_szManagerName[pInstate->m_btNewPos], szName);
  598. m_dwManagerID[pInstate->m_btNewPos] = g_String2Id(szName);
  599. m_szManagerName[pInstate->m_btCurPos][0] = 0;
  600. m_dwManagerID[pInstate->m_btCurPos] = 0;
  601. strcpy(pSync->m_szTitle, m_szManagerTitle[pInstate->m_btNewPos]);
  602. break;
  603. case enumTONG_FIGURE_MEMBER:
  604. if (!AddMember(szName))
  605. return FALSE;
  606. m_szManagerName[pInstate->m_btCurPos][0] = 0;
  607. m_dwManagerID[pInstate->m_btCurPos] = 0;
  608. m_nManagerNum--;
  609. strcpy(pSync->m_szTitle, m_szNormalTitle);
  610. break;
  611. default:
  612. return FALSE;
  613. }
  614. }
  615. else if (pInstate->m_btCurFigure == enumTONG_FIGURE_MEMBER)
  616. {
  617. if (!m_psMember)
  618. return FALSE;
  619. int nPos = -1;
  620. DWORD dwNameID = g_String2Id(szName);
  621. if (dwNameID == 0)
  622. return FALSE;
  623. for (int i = 0; i < m_nMemberPointSize; i++)
  624. {
  625. if (m_psMember[i].m_dwNameID != dwNameID)
  626. continue;
  627. nPos = i;
  628. break;
  629. }
  630. if (nPos < 0)
  631. return FALSE;
  632. switch (pInstate->m_btNewFigure)
  633. {
  634. case enumTONG_FIGURE_DIRECTOR:
  635. if (pInstate->m_btNewPos >= defTONG_MAX_DIRECTOR)
  636. return FALSE;
  637. if (m_szDirectorName[pInstate->m_btNewPos][0])
  638. return FALSE;
  639. strcpy(m_szDirectorName[pInstate->m_btNewPos], szName);
  640. m_dwDirectorID[pInstate->m_btNewPos] = g_String2Id(szName);
  641. this->m_psMember[nPos].m_szName[0] = 0;
  642. this->m_psMember[nPos].m_dwNameID = 0;
  643. m_nDirectorNum++;
  644. m_nMemberNum--;
  645. strcpy(pSync->m_szTitle, m_szDirectorTitle[pInstate->m_btNewPos]);
  646. break;
  647. case enumTONG_FIGURE_MANAGER:
  648. if (pInstate->m_btNewPos >= defTONG_MAX_MANAGER)
  649. return FALSE;
  650. if (m_szManagerName[pInstate->m_btNewPos][0])
  651. return FALSE;
  652. strcpy(m_szManagerName[pInstate->m_btNewPos], szName);
  653. m_dwManagerID[pInstate->m_btNewPos] = g_String2Id(szName);
  654. this->m_psMember[nPos].m_szName[0] = 0;
  655. this->m_psMember[nPos].m_dwNameID = 0;
  656. m_nManagerNum++;
  657. m_nMemberNum--;
  658. strcpy(pSync->m_szTitle, m_szManagerTitle[pInstate->m_btNewPos]);
  659. break;
  660. default:
  661. return FALSE;
  662. }
  663. }
  664. pSync->m_btSuccessFlag = 1;
  665. {{
  666. CNetConnectDup conndup;
  667. DWORD nameid = 0;
  668. unsigned long param = 0;
  669. if (g_HostServer.FindPlayerByRole(NULL, std::_tstring(szName), &conndup, NULL, &nameid, &param))
  670. {
  671. CNetConnectDup tongconndup = g_TongServer.FindTongConnectByIP(conndup.GetIP());
  672. if (tongconndup.IsValid())
  673. {
  674. STONG_BE_INSTATED_SYNC sSync;
  675. sSync.ProtocolFamily = pf_tong;
  676. sSync.ProtocolID = enumS2C_TONG_BE_INSTATED;
  677. sSync.m_btFigure = pInstate->m_btNewFigure;
  678. sSync.m_btPos = pInstate->m_btNewPos;
  679. sSync.m_dwParam = param;
  680. strcpy(sSync.m_szName, szName);
  681. switch (pInstate->m_btNewFigure)
  682. {
  683. case enumTONG_FIGURE_DIRECTOR:
  684. strcpy(sSync.m_szTitle, m_szDirectorTitle[pInstate->m_btNewPos]);
  685. break;
  686. case enumTONG_FIGURE_MANAGER:
  687. strcpy(sSync.m_szTitle, m_szManagerTitle[pInstate->m_btNewPos]);
  688. break;
  689. case enumTONG_FIGURE_MEMBER:
  690. strcpy(sSync.m_szTitle, this->m_szNormalTitle);
  691. break;
  692. }
  693. tongconndup.SendPackage((const void *)&sSync, sizeof(sSync));
  694. }
  695. else
  696. {
  697. //tong is not connect
  698. }
  699. }
  700. else
  701. {
  702. //not find
  703. }
  704. }}
  705. // 向帮会频道发消息,某人被任命
  706. char szMsg[96];
  707. sprintf(szMsg, "\O%u", m_dwNameID);
  708. DWORD channid = g_ChannelMgr.GetChannelID(szMsg, 0);
  709. if (channid != -1)
  710. {
  711. if (pSync->m_szTitle[0])
  712. sprintf(szMsg, "%s被任命为%s!", szName, pSync->m_szTitle);
  713. else
  714. {
  715. switch (pSync->m_btNewFigure)
  716. {
  717. case enumTONG_FIGURE_DIRECTOR:
  718. sprintf(szMsg, "%s被任命为长老!", szName);
  719. break;
  720. case enumTONG_FIGURE_MANAGER:
  721. sprintf(szMsg, "%s被任命为队长!", szName);
  722. break;
  723. case enumTONG_FIGURE_MEMBER:
  724. sprintf(szMsg, "%s被任命为普通帮众!", szName);
  725. break;
  726. }
  727. }
  728. g_ChannelMgr.SayOnChannel(channid, TRUE, std::string(), std::string("公告"), std::string(szMsg));
  729. }
  730. // 存盘,数据保存至数据库
  731. TMemberStruct sMember;
  732. sMember.MemberClass = (TONG_MEMBER_FIGURE)pInstate->m_btNewFigure;
  733. sMember.nTitleIndex = pInstate->m_btNewPos;
  734. strcpy(sMember.szTong, this->m_szName);
  735. strcpy(sMember.szName, szName);
  736. g_cTongDB.ChangeMember(sMember);
  737. return TRUE;
  738. }
  739. */
  740. BOOL CTongControl::Kick(STONG_KICK_COMMAND *pKick, STONG_KICK_SYNC *pSync)
  741. {
  742. if (!pKick || !pSync)
  743. return FALSE;
  744. char szName[32];
  745. DWORD dwNameID;
  746. int nKickPos;
  747. memcpy(szName, pKick->m_szName, sizeof(pKick->m_szName));
  748. szName[31] = 0;
  749. dwNameID = g_String2Id(szName);
  750. if (dwNameID == 0)
  751. return FALSE;
  752. pSync->ProtocolFamily = pf_tong;
  753. pSync->ProtocolID = enumS2C_TONG_KICK;
  754. pSync->m_btFigure = pKick->m_btFigure;
  755. pSync->m_btPos = pKick->m_btPos;
  756. pSync->m_dwParam = pKick->m_dwParam;
  757. pSync->m_dwTongNameID = pKick->m_dwTongNameID;
  758. pSync->m_btSuccessFlag = 0;
  759. strcpy(pSync->m_szName, szName);
  760. if (pKick->m_btFigure == enumTONG_FIGURE_MANAGER)
  761. {
  762. if (pKick->m_btPos >= defTONG_MAX_MANAGER)
  763. return FALSE;
  764. for (int i = 0; i < defTONG_MAX_MANAGER; i++)
  765. {
  766. if (m_dwManagerID[i] == dwNameID && strcmp(m_szManagerName[i], szName) == 0)
  767. break;
  768. }
  769. if (i >= defTONG_MAX_MANAGER)
  770. return FALSE;
  771. nKickPos = i;
  772. this->m_szManagerName[i][0] = 0;
  773. this->m_dwManagerID[i] = 0;
  774. this->m_nManagerNum--;
  775. }
  776. else if (pKick->m_btFigure == enumTONG_FIGURE_MEMBER)
  777. {
  778. if (!m_psMember)
  779. return FALSE;
  780. int nPos = -1;
  781. DWORD dwNameID = g_String2Id(szName);
  782. if (dwNameID == 0)
  783. return FALSE;
  784. for (int i = 0; i < m_nMemberPointSize; i++)
  785. {
  786. if (m_psMember[i].m_dwNameID != dwNameID)
  787. continue;
  788. nPos = i;
  789. break;
  790. }
  791. if (nPos < 0)
  792. return FALSE;
  793. if (!m_psMember[nPos].m_szName[0] ||
  794. strcmp(m_psMember[nPos].m_szName, szName) != 0)
  795. return FALSE;
  796. m_psMember[nPos].m_szName[0] = 0;
  797. m_psMember[nPos].m_dwNameID = 0;
  798. m_nMemberNum--;
  799. nKickPos = 0;
  800. }
  801. else
  802. {
  803. return FALSE;
  804. }
  805. pSync->m_btSuccessFlag = 1;
  806. pSync->m_btPos = nKickPos;
  807. {{
  808. CNetConnectDup conndup;
  809. DWORD nameid = 0;
  810. unsigned long param = 0;
  811. if (g_HostServer.FindPlayerByRole(NULL, std::_tstring(szName), &conndup, NULL, &nameid, &param))
  812. {
  813. CNetConnectDup tongconndup = g_TongServer.FindTongConnectByIP(conndup.GetIP());
  814. if (tongconndup.IsValid())
  815. {
  816. STONG_BE_KICKED_SYNC sSync;
  817. sSync.ProtocolFamily = pf_tong;
  818. sSync.ProtocolID = enumS2C_TONG_BE_KICKED;
  819. sSync.m_btFigure = pKick->m_btFigure;
  820. sSync.m_btPos = nKickPos;
  821. sSync.m_dwParam = param;
  822. strcpy(sSync.m_szName, szName);
  823. tongconndup.SendPackage((const void *)&sSync, sizeof(sSync));
  824. }
  825. else
  826. {
  827. //tong is not connect
  828. }
  829. }
  830. else
  831. {
  832. //not find
  833. }
  834. }}
  835. // 存盘
  836. g_cTongDB.DelMember(szName);
  837. // 向帮会频道发消息,某人被踢出帮会
  838. char szMsg[96];
  839. sprintf(szMsg, "\O%u", m_dwNameID);
  840. DWORD channid = g_ChannelMgr.GetChannelID(szMsg, 0);
  841. if (channid != -1)
  842. {
  843. sprintf(szMsg, "%s被踢出帮会!", szName);
  844. g_ChannelMgr.SayOnChannel(channid, TRUE, std::string(), std::string("公告"), std::string(szMsg));
  845. }
  846. return TRUE;
  847. }
  848. BOOL CTongControl::Leave(STONG_LEAVE_COMMAND *pLeave, STONG_LEAVE_SYNC *pSync)
  849. {
  850. if (!pLeave || !pSync)
  851. return FALSE;
  852. char szName[32];
  853. memcpy(szName, pLeave->m_szName, sizeof(pLeave->m_szName));
  854. szName[31] = 0;
  855. pSync->ProtocolFamily = pf_tong;
  856. pSync->ProtocolID = enumS2C_TONG_LEAVE;
  857. pSync->m_dwParam = pLeave->m_dwParam;
  858. pSync->m_btSuccessFlag = 0;
  859. strcpy(pSync->m_szName, szName);
  860. switch (pLeave->m_btFigure)
  861. {
  862. case enumTONG_FIGURE_MEMBER:
  863. {
  864. if (!m_psMember)
  865. break;
  866. int nPos = -1;
  867. DWORD dwNameID = g_String2Id(szName);
  868. if (dwNameID == 0)
  869. return FALSE;
  870. for (int i = 0; i < m_nMemberPointSize; i++)
  871. {
  872. if (m_psMember[i].m_dwNameID != dwNameID)
  873. continue;
  874. nPos = i;
  875. break;
  876. }
  877. if (nPos < 0)
  878. return FALSE;
  879. if (!m_psMember[nPos].m_szName[0] ||
  880. strcmp(m_psMember[nPos].m_szName, szName) != 0)
  881. return FALSE;
  882. m_psMember[nPos].m_szName[0] = 0;
  883. m_psMember[nPos].m_dwNameID = 0;
  884. m_nMemberNum--;
  885. }
  886. break;
  887. case enumTONG_FIGURE_MANAGER:
  888. {
  889. if (pLeave->m_btPos >= 0 && pLeave->m_btPos < defTONG_MAX_MANAGER)
  890. {
  891. if (strcmp(m_szManagerName[pLeave->m_btPos], szName) == 0)
  892. {
  893. m_szManagerName[pLeave->m_btPos][0] = 0;
  894. m_dwManagerID[pLeave->m_btPos] = 0;
  895. m_nManagerNum--;
  896. break;
  897. }
  898. }
  899. int nPos = -1;
  900. DWORD dwNameID = g_String2Id(szName);
  901. if (dwNameID == 0)
  902. return FALSE;
  903. for (int i = 0; i < defTONG_MAX_MANAGER; i++)
  904. {
  905. if (m_dwManagerID[i] != dwNameID)
  906. continue;
  907. nPos = i;
  908. break;
  909. }
  910. if (nPos < 0)
  911. return FALSE;
  912. if (!m_szManagerName[nPos][0] ||
  913. strcmp(szName, m_szManagerName[nPos]) != 0)
  914. return FALSE;
  915. m_szManagerName[nPos][0] = 0;
  916. m_dwManagerID[nPos] = 0;
  917. m_nManagerNum--;
  918. }
  919. break;
  920. case enumTONG_FIGURE_DIRECTOR:
  921. return FALSE;
  922. case enumTONG_FIGURE_MASTER:
  923. return FALSE;
  924. }
  925. pSync->m_btSuccessFlag = 1;
  926. // 存盘
  927. g_cTongDB.DelMember(szName);
  928. // 通过帮会频道发布消息:某某人叛帮
  929. char szMsg[96];
  930. sprintf(szMsg, "\O%u", m_dwNameID);
  931. DWORD channid = g_ChannelMgr.GetChannelID(szMsg, 0);
  932. if (channid != -1)
  933. {
  934. sprintf(szMsg, "%s叛出本帮!", szName);
  935. g_ChannelMgr.SayOnChannel(channid, TRUE, std::string(), std::string("公告"), std::string(szMsg));
  936. }
  937. return TRUE;
  938. }
  939. BOOL CTongControl::AcceptMaster(STONG_ACCEPT_MASTER_COMMAND *pAccept)
  940. {
  941. if (!pAccept)
  942. return FALSE;
  943. char szName[32], szOldMaster[32];
  944. memcpy(szName, pAccept->m_szName, sizeof(pAccept->m_szName));
  945. szName[31] = 0;
  946. if (!szName[0])
  947. return FALSE;
  948. strcpy(szOldMaster, this->m_szMasterName);
  949. // 能力不够
  950. if (pAccept->m_btAcceptFalg == 0)
  951. {
  952. CNetConnectDup conndup;
  953. DWORD nameid = 0;
  954. unsigned long param = 0;
  955. if (g_HostServer.FindPlayerByRole(NULL, std::_tstring(m_szMasterName), &conndup, NULL, &nameid, &param))
  956. {
  957. CNetConnectDup tongconndup = g_TongServer.FindTongConnectByIP(conndup.GetIP());
  958. if (tongconndup.IsValid())
  959. {
  960. STONG_CHANGE_MASTER_FAIL_SYNC sFail;
  961. sFail.ProtocolFamily = pf_tong;
  962. sFail.ProtocolID = enumS2C_TONG_CHANGE_MASTER_FAIL;
  963. sFail.m_dwParam = param;
  964. sFail.m_btFailID = 1;
  965. sFail.m_dwTongNameID = pAccept->m_dwTongNameID;
  966. memcpy(sFail.m_szName, szName, sizeof(szName));
  967. tongconndup.SendPackage((const void *)&sFail, sizeof(sFail));
  968. }
  969. else
  970. {
  971. //tong is not connect
  972. }
  973. }
  974. else
  975. {
  976. //not find
  977. }
  978. return FALSE;
  979. }
  980. DWORD dwNameID;
  981. int i;
  982. dwNameID = g_String2Id(szName);
  983. if (dwNameID == 0)
  984. return FALSE;
  985. if (pAccept->m_btFigure == enumTONG_FIGURE_DIRECTOR)
  986. {
  987. for (i = 0; i < defTONG_MAX_DIRECTOR; i++)
  988. {
  989. if (m_dwDirectorID[i] == dwNameID && strcmp(szName, m_szDirectorName[i]) == 0)
  990. break;
  991. }
  992. if (i >= defTONG_MAX_DIRECTOR)
  993. return FALSE;
  994. if (!AddMember(m_szMasterName))
  995. return FALSE;
  996. strcpy(this->m_szMasterName, szName);
  997. this->m_dwMasterID = dwNameID;
  998. m_szDirectorName[i][0] = 0;
  999. m_dwDirectorID[i] = 0;
  1000. this->m_nDirectorNum--;
  1001. }
  1002. else if (pAccept->m_btFigure == enumTONG_FIGURE_MANAGER)
  1003. {
  1004. for (i = 0; i < defTONG_MAX_MANAGER; i++)
  1005. {
  1006. if (m_dwManagerID[i] == dwNameID && strcmp(szName, m_szManagerName[i]) == 0)
  1007. break;
  1008. }
  1009. if (i >= defTONG_MAX_MANAGER)
  1010. return FALSE;
  1011. if (!AddMember(m_szMasterName))
  1012. return FALSE;
  1013. strcpy(this->m_szMasterName, szName);
  1014. this->m_dwMasterID = dwNameID;
  1015. m_szManagerName[i][0] = 0;
  1016. m_dwManagerID[i] = 0;
  1017. this->m_nManagerNum--;
  1018. }
  1019. else if (pAccept->m_btFigure == enumTONG_FIGURE_MEMBER)
  1020. {
  1021. if (!m_psMember || m_nMemberPointSize <= 0)
  1022. return FALSE;
  1023. for (i = 0; i < this->m_nMemberPointSize; i++)
  1024. {
  1025. if (m_psMember[i].m_dwNameID == dwNameID &&
  1026. strcmp(szName, m_psMember[i].m_szName) == 0)
  1027. break;
  1028. }
  1029. if (i >= m_nMemberPointSize)
  1030. return FALSE;
  1031. if (!AddMember(m_szMasterName))
  1032. return FALSE;
  1033. strcpy(m_szMasterName, szName);
  1034. m_dwMasterID = dwNameID;
  1035. m_psMember[i].m_szName[0] = 0;
  1036. m_psMember[i].m_dwNameID = 0;
  1037. m_nMemberNum--;
  1038. }
  1039. else
  1040. {
  1041. return FALSE;
  1042. }
  1043. STONG_CHANGE_AS_SYNC sChange;
  1044. sChange.ProtocolFamily = pf_tong;
  1045. sChange.ProtocolID = enumS2C_TONG_CHANGE_AS;
  1046. sChange.m_dwTongNameID = this->m_dwNameID;
  1047. // 给老帮主发消息
  1048. DWORD nameid = 0;
  1049. unsigned long param = 0;
  1050. CNetConnectDup conndup1;
  1051. if (g_HostServer.FindPlayerByRole(NULL, std::_tstring(szOldMaster), &conndup1, NULL, &nameid, &param))
  1052. {
  1053. CNetConnectDup tongconndup = g_TongServer.FindTongConnectByIP(conndup1.GetIP());
  1054. if (tongconndup.IsValid())
  1055. {
  1056. sChange.m_dwParam = param;
  1057. sChange.m_btFigure = enumTONG_FIGURE_MEMBER;
  1058. sChange.m_btPos = 0;
  1059. strcpy(sChange.m_szTitle, m_szNormalTitle);
  1060. strcpy(sChange.m_szName, m_szMasterName);
  1061. tongconndup.SendPackage((const void *)&sChange, sizeof(sChange));
  1062. }
  1063. }
  1064. // 给新帮主发消息
  1065. CNetConnectDup conndup2;
  1066. if (g_HostServer.FindPlayerByRole(NULL, std::_tstring(szName), &conndup2, NULL, &nameid, &param))
  1067. {
  1068. CNetConnectDup tongconndup = g_TongServer.FindTongConnectByIP(conndup2.GetIP());
  1069. if (tongconndup.IsValid())
  1070. {
  1071. sChange.m_dwParam = param;
  1072. sChange.m_btFigure = enumTONG_FIGURE_MASTER;
  1073. sChange.m_btPos = 0;
  1074. strcpy(sChange.m_szTitle, this->m_szMasterTitle);
  1075. strcpy(sChange.m_szName, this->m_szMasterName);
  1076. tongconndup.SendPackage((const void *)&sChange, sizeof(sChange));
  1077. }
  1078. }
  1079. STONG_CHANGE_MASTER_SYNC sMaster;
  1080. sMaster.ProtocolFamily = pf_tong;
  1081. sMaster.ProtocolID = enumS2C_TONG_CHANGE_AS;
  1082. sMaster.m_dwTongNameID = m_dwNameID;
  1083. strcpy(sMaster.m_szName, m_szMasterName);
  1084. g_TongServer.BroadPackage((const void*)&sMaster, sizeof(sMaster));
  1085. // 存盘
  1086. // 新帮主
  1087. TMemberStruct sMember1;
  1088. sMember1.MemberClass = enumTONG_FIGURE_MASTER;
  1089. sMember1.nTitleIndex = 0;
  1090. strcpy(sMember1.szTong, this->m_szName);
  1091. strcpy(sMember1.szName, szName);
  1092. g_cTongDB.ChangeMember(sMember1);
  1093. // 老帮主
  1094. TMemberStruct sMember2;
  1095. sMember2.MemberClass = enumTONG_FIGURE_MEMBER;
  1096. sMember2.nTitleIndex = 0;
  1097. strcpy(sMember2.szTong, this->m_szName);
  1098. strcpy(sMember2.szName, szOldMaster);
  1099. g_cTongDB.ChangeMember(sMember2);
  1100. // 聊天频道发消息
  1101. char szMsg[96];
  1102. sprintf(szMsg, "\O%u", m_dwNameID);
  1103. DWORD channid = g_ChannelMgr.GetChannelID(szMsg, 0);
  1104. if (channid != -1)
  1105. {
  1106. sprintf(szMsg, "%s把帮主之位传给了%s!", szOldMaster, szName);
  1107. g_ChannelMgr.SayOnChannel(channid, TRUE, std::string(), std::string("公告"), std::string(szMsg));
  1108. }
  1109. return TRUE;
  1110. }
  1111. BOOL CTongControl::GetLoginData(STONG_GET_LOGIN_DATA_COMMAND *pLogin, STONG_LOGIN_DATA_SYNC *pSync)
  1112. {
  1113. if (!pLogin || !pSync)
  1114. return FALSE;
  1115. int i;
  1116. DWORD dwNameID = g_String2Id(pLogin->m_szName);
  1117. if (dwNameID == 0)
  1118. return FALSE;
  1119. pSync->m_btCamp = this->m_nCamp;
  1120. strcpy(pSync->m_szTongName, this->m_szName);
  1121. strcpy(pSync->m_szMaster, this->m_szMasterName);
  1122. strcpy(pSync->m_szName, pLogin->m_szName);
  1123. if (this->m_dwMasterID == dwNameID)
  1124. {
  1125. pSync->m_btFigure = enumTONG_FIGURE_MASTER;
  1126. pSync->m_btPos = 0;
  1127. pSync->m_btFlag = 1;
  1128. strcpy(pSync->m_szTitle, this->m_szMasterTitle);
  1129. return TRUE;
  1130. }
  1131. for (i = 0; i < defTONG_MAX_DIRECTOR; i++)
  1132. {
  1133. if (this->m_dwDirectorID[i] == dwNameID)
  1134. {
  1135. pSync->m_btFigure = enumTONG_FIGURE_DIRECTOR;
  1136. pSync->m_btPos = i;
  1137. pSync->m_btFlag = 1;
  1138. strcpy(pSync->m_szTitle, this->m_szDirectorTitle[i]);
  1139. return TRUE;
  1140. }
  1141. }
  1142. for (i = 0; i < defTONG_MAX_MANAGER; i++)
  1143. {
  1144. if (this->m_dwManagerID[i] == dwNameID)
  1145. {
  1146. pSync->m_btFigure = enumTONG_FIGURE_MANAGER;
  1147. pSync->m_btPos = i;
  1148. pSync->m_btFlag = 1;
  1149. strcpy(pSync->m_szTitle, this->m_szManagerTitle[i]);
  1150. return TRUE;
  1151. }
  1152. }
  1153. if (this->m_psMember)
  1154. {
  1155. for (i = 0; i < this->m_nMemberPointSize; i++)
  1156. {
  1157. if (m_psMember[i].m_dwNameID == dwNameID)
  1158. {
  1159. pSync->m_btFigure = enumTONG_FIGURE_MEMBER;
  1160. pSync->m_btPos = 0;
  1161. pSync->m_btFlag = 1;
  1162. strcpy(pSync->m_szTitle, this->m_szNormalTitle);
  1163. return TRUE;
  1164. }
  1165. }
  1166. }
  1167. return FALSE;
  1168. }
  1169. BOOL CTongControl::SearchOne(char *lpszName, STONG_ONE_LEADER_INFO *pInfo)
  1170. {
  1171. if (!lpszName || !lpszName[0] || !pInfo)
  1172. return FALSE;
  1173. int i;
  1174. DWORD dwNameID = g_String2Id(lpszName);
  1175. if (dwNameID == 0)
  1176. return FALSE;
  1177. if (m_dwMasterID == dwNameID)
  1178. {
  1179. pInfo->m_btFigure = enumTONG_FIGURE_MASTER;
  1180. pInfo->m_btPos = 0;
  1181. strcpy(pInfo->m_szTitle, m_szMasterTitle);
  1182. strcpy(pInfo->m_szName, m_szMasterName);
  1183. return TRUE;
  1184. }
  1185. for (i = 0; i < defTONG_MAX_DIRECTOR; i++)
  1186. {
  1187. if (m_dwDirectorID[i] == dwNameID)
  1188. {
  1189. pInfo->m_btFigure = enumTONG_FIGURE_DIRECTOR;
  1190. pInfo->m_btPos = i;
  1191. strcpy(pInfo->m_szTitle, m_szDirectorTitle[i]);
  1192. strcpy(pInfo->m_szName, m_szDirectorName[i]);
  1193. return TRUE;
  1194. }
  1195. }
  1196. for (i = 0; i < defTONG_MAX_MANAGER; i++)
  1197. {
  1198. if (m_dwManagerID[i] == dwNameID)
  1199. {
  1200. pInfo->m_btFigure = enumTONG_FIGURE_MANAGER;
  1201. pInfo->m_btPos = i;
  1202. strcpy(pInfo->m_szTitle, m_szManagerTitle[i]);
  1203. strcpy(pInfo->m_szName, m_szManagerName[i]);
  1204. return TRUE;
  1205. }
  1206. }
  1207. if (m_psMember)
  1208. {
  1209. for (i = 0; i < m_nMemberPointSize; i++)
  1210. {
  1211. if (m_psMember[i].m_dwNameID == dwNameID)
  1212. {
  1213. pInfo->m_btFigure = enumTONG_FIGURE_MEMBER;
  1214. pInfo->m_btPos = 0;
  1215. strcpy(pInfo->m_szTitle, m_szNormalTitle);
  1216. strcpy(pInfo->m_szName, m_psMember[i].m_szName);
  1217. return TRUE;
  1218. }
  1219. }
  1220. }
  1221. return FALSE;
  1222. }