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

模拟服务器

开发平台:

C/C++

  1. //---------------------------------------------------------------------------
  2. // Sword3 Engine (c) 2003 by Kingsoft
  3. //
  4. // File: KPlayerTong.cpp
  5. // Date: 2003.08.12
  6. // Code: 边城浪子
  7. // Desc: KPlayerTong Class
  8. //---------------------------------------------------------------------------
  9. #include "KCore.h"
  10. #include "KNpc.h"
  11. #include "KPlayer.h"
  12. #include "KPlayerSet.h"
  13. #include "KPlayerTong.h"
  14. #ifndef _SERVER
  15. #include "CoreShell.h"
  16. #endif
  17. //#define defTONG_NAME_LENGTH 8
  18. #define defFuncShowNormalMsg(str)
  19. {
  20. KSystemMessage sMsg;
  21. sMsg.eType = SMT_NORMAL;
  22. sMsg.byConfirmType = SMCT_NONE;
  23. sMsg.byPriority = 0;
  24. sMsg.byParamSize = 0;
  25. sprintf(sMsg.szMessage, str);
  26. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  27. }
  28. //-------------------------------------------------------------------------
  29. // 功能:初始化
  30. //-------------------------------------------------------------------------
  31. void KPlayerTong::Init(int nPlayerIdx)
  32. {
  33. m_nPlayerIndex = nPlayerIdx;
  34. Clear();
  35. }
  36. //-------------------------------------------------------------------------
  37. // 功能:清空
  38. //-------------------------------------------------------------------------
  39. void KPlayerTong::Clear()
  40. {
  41. m_nFlag = 0;
  42. m_nFigure = enumTONG_FIGURE_MEMBER;
  43. m_nCamp = 0;
  44. m_dwTongNameID = 0;
  45. m_szName[0] = 0;
  46. m_szTitle[0] = 0;
  47. m_szMasterName[0] = 0;
  48. m_nApplyTo = 0;
  49. }
  50. #ifndef _SERVER
  51. //-------------------------------------------------------------------------
  52. // 功能:申请创建帮会
  53. //-------------------------------------------------------------------------
  54. BOOL KPlayerTong::ApplyCreateTong(int nCamp, char *lpszTongName)
  55. {
  56. defFuncShowNormalMsg(MSG_TONG_APPLY_CREATE);
  57. // 帮会名问题
  58. if (!lpszTongName || !lpszTongName[0] || strlen(lpszTongName) > defTONG_NAME_MAX_LENGTH)
  59. {
  60. defFuncShowNormalMsg(MSG_TONG_CREATE_ERROR01);
  61. return FALSE;
  62. }
  63. // 帮会阵营问题
  64. if (nCamp != camp_justice && nCamp != camp_evil && nCamp != camp_balance)
  65. {
  66. defFuncShowNormalMsg(MSG_TONG_CREATE_ERROR02);
  67. return FALSE;
  68. }
  69. // 已经是帮会成员
  70. if (m_nFlag)
  71. {
  72. defFuncShowNormalMsg(MSG_TONG_CREATE_ERROR03);
  73. return FALSE;
  74. }
  75. // 自己的阵营问题
  76. if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentCamp != camp_free)
  77. {
  78. defFuncShowNormalMsg(MSG_TONG_CREATE_ERROR04);
  79. return FALSE;
  80. }
  81. // 等级问题
  82. if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_Level < PlayerSet.m_sTongParam.m_nLevel)
  83. {
  84. defFuncShowNormalMsg(MSG_TONG_CREATE_ERROR05);
  85. return FALSE;
  86. }
  87. if ((int)Player[CLIENT_PLAYER_INDEX].m_dwLeadLevel < PlayerSet.m_sTongParam.m_nLeadLevel)
  88. {
  89. defFuncShowNormalMsg(MSG_TONG_CREATE_ERROR06);
  90. return FALSE;
  91. }
  92. // 交易过程中
  93. if (Player[CLIENT_PLAYER_INDEX].CheckTrading())
  94. {
  95. return FALSE;
  96. }
  97. // 钱问题
  98. if (Player[CLIENT_PLAYER_INDEX].m_ItemList.GetMoneyAmount() < PlayerSet.m_sTongParam.m_nMoney)
  99. {
  100. char szBuf[80];
  101. sprintf(szBuf, MSG_TONG_CREATE_ERROR07, PlayerSet.m_sTongParam.m_nMoney);
  102. defFuncShowNormalMsg(szBuf);
  103. return FALSE;
  104. }
  105. // 组队不能建帮会
  106. if (Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag)
  107. {
  108. defFuncShowNormalMsg(MSG_TONG_CREATE_ERROR08);
  109. return FALSE;
  110. }
  111. TONG_APPLY_CREATE_COMMAND sApply;
  112. sApply.ProtocolType = c2s_extendtong;
  113. sApply.m_wLength = sizeof(TONG_APPLY_CREATE_COMMAND) - 1;
  114. sApply.m_btMsgId = enumTONG_COMMAND_ID_APPLY_CREATE;
  115. sApply.m_btCamp = (BYTE)nCamp;
  116. strcpy(sApply.m_szName, lpszTongName);
  117. if (g_pClient)
  118. g_pClient->SendPackToServer(&sApply, sApply.m_wLength + 1);
  119. return TRUE;
  120. }
  121. #endif
  122. #ifndef _SERVER
  123. //-------------------------------------------------------------------------
  124. // 功能:申请加入帮会
  125. //-------------------------------------------------------------------------
  126. BOOL KPlayerTong::ApplyAddTong(DWORD dwNpcID)
  127. {
  128. defFuncShowNormalMsg(MSG_TONG_APPLY_ADD);
  129. // 已经是帮会成员
  130. if (m_nFlag)
  131. {
  132. defFuncShowNormalMsg(MSG_TONG_APPLY_ADD_ERROR1);
  133. return FALSE;
  134. }
  135. // 自己的阵营问题
  136. if (Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentCamp != camp_free)
  137. {
  138. defFuncShowNormalMsg(MSG_TONG_APPLY_ADD_ERROR2);
  139. return FALSE;
  140. }
  141. // 交易过程中
  142. if (Player[CLIENT_PLAYER_INDEX].CheckTrading())
  143. {
  144. return FALSE;
  145. }
  146. // 组队不能建帮会
  147. if (Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag)
  148. {
  149. defFuncShowNormalMsg(MSG_TONG_APPLY_ADD_ERROR3);
  150. return FALSE;
  151. }
  152. TONG_APPLY_ADD_COMMAND sApply;
  153. sApply.ProtocolType = c2s_extendtong;
  154. sApply.m_wLength = sizeof(TONG_APPLY_ADD_COMMAND) - 1;
  155. sApply.m_btMsgId = enumTONG_COMMAND_ID_APPLY_ADD;
  156. sApply.m_dwNpcID = dwNpcID;
  157. if (g_pClient)
  158. g_pClient->SendPackToServer(&sApply, sizeof(TONG_APPLY_ADD_COMMAND));
  159. return TRUE;
  160. }
  161. #endif
  162. #ifdef _SERVER
  163. //-------------------------------------------------------------------------
  164. // 功能:判断创建帮会条件是否成立
  165. //-------------------------------------------------------------------------
  166. int KPlayerTong::CheckCreateCondition(int nCamp, char *lpszTongName)
  167. {
  168. if (Player[m_nPlayerIndex].m_nIndex <= 0)
  169. return enumTONG_CREATE_ERROR_ID1;
  170. // 交易过程中
  171. if (Player[m_nPlayerIndex].CheckTrading())
  172. return enumTONG_CREATE_ERROR_ID2;
  173. // 帮会名问题
  174. if (!lpszTongName || !lpszTongName[0] || strlen(lpszTongName) > defTONG_NAME_MAX_LENGTH)
  175. return enumTONG_CREATE_ERROR_ID3;
  176. // 帮会阵营问题
  177. if (nCamp != camp_justice && nCamp != camp_evil && nCamp != camp_balance)
  178. return enumTONG_CREATE_ERROR_ID4;
  179. // 已经是帮会成员
  180. if (m_nFlag)
  181. return enumTONG_CREATE_ERROR_ID5;
  182. // 自己的阵营问题
  183. if (Npc[Player[m_nPlayerIndex].m_nIndex].m_CurrentCamp != camp_free ||
  184. Npc[Player[m_nPlayerIndex].m_nIndex].m_Camp != camp_free)
  185. return enumTONG_CREATE_ERROR_ID6;
  186. // 等级问题
  187. if (Npc[Player[m_nPlayerIndex].m_nIndex].m_Level < PlayerSet.m_sTongParam.m_nLevel || 
  188. (int)Player[m_nPlayerIndex].m_dwLeadLevel < PlayerSet.m_sTongParam.m_nLeadLevel)
  189. return enumTONG_CREATE_ERROR_ID7;
  190. // 钱问题
  191. if (Player[m_nPlayerIndex].m_ItemList.GetMoneyAmount() < PlayerSet.m_sTongParam.m_nMoney)
  192. return enumTONG_CREATE_ERROR_ID8;
  193. // 组队不能建帮会
  194. if (Player[m_nPlayerIndex].m_cTeam.m_nFlag)
  195. return enumTONG_CREATE_ERROR_ID9;
  196. return 0;
  197. }
  198. #endif
  199. #ifdef _SERVER
  200. //-------------------------------------------------------------------------
  201. // 功能:得到relay通知,帮会创建成功,处理相应数据
  202. //-------------------------------------------------------------------------
  203. BOOL KPlayerTong::Create(int nCamp, char *lpszTongName)
  204. {
  205. // if (!CheckCreateCondition(nCamp, lpszTongName))
  206. // return FALSE;
  207. m_nFlag = 1;
  208. m_nFigure = enumTONG_FIGURE_MASTER;
  209. m_nCamp = nCamp;
  210. m_szTitle[0] = 0;
  211. strcpy(m_szName, lpszTongName);
  212. strcpy(m_szMasterName, Npc[Player[m_nPlayerIndex].m_nIndex].Name);
  213. m_dwTongNameID = g_FileName2Id(m_szName);
  214. Npc[Player[m_nPlayerIndex].m_nIndex].m_Camp = m_nCamp;
  215. Npc[Player[m_nPlayerIndex].m_nIndex].m_CurrentCamp = m_nCamp;
  216. Player[m_nPlayerIndex].m_ItemList.DecMoney(PlayerSet.m_sTongParam.m_nMoney);
  217. // 通知客户端
  218. TONG_CREATE_SYNC sCreate;
  219. sCreate.ProtocolType = s2c_tongcreate;
  220. sCreate.m_btCamp = nCamp;
  221. if (strlen(lpszTongName) < sizeof(sCreate.m_szName))
  222. strcpy(sCreate.m_szName, lpszTongName);
  223. else
  224. {
  225. memcpy(sCreate.m_szName, lpszTongName, sizeof(sCreate.m_szName) - 1);
  226. sCreate.m_szName[sizeof(sCreate.m_szName) - 1] = 0;
  227. }
  228. if (g_pServer)
  229. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, &sCreate, sizeof(TONG_CREATE_SYNC));
  230. return TRUE;
  231. }
  232. #endif
  233. #ifndef _SERVER
  234. //-------------------------------------------------------------------------
  235. // 功能:得到服务器通知创建帮会
  236. //-------------------------------------------------------------------------
  237. void KPlayerTong::Create(TONG_CREATE_SYNC *psCreate)
  238. {
  239. if (!psCreate)
  240. return;
  241. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_Camp = psCreate->m_btCamp;
  242. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentCamp = psCreate->m_btCamp;
  243. m_nFlag = 1;
  244. m_nFigure = enumTONG_FIGURE_MASTER;
  245. m_nCamp = psCreate->m_btCamp;
  246. m_szTitle[0] = 0;
  247. memset(m_szName, 0, sizeof(m_szName));
  248. memcpy(m_szName, psCreate->m_szName, sizeof(psCreate->m_szName));
  249. strcpy(m_szMasterName, Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name);
  250. m_dwTongNameID = g_FileName2Id(m_szName);
  251. // 通知界面帮会建立成功
  252. defFuncShowNormalMsg(MSG_TONG_CREATE_SUCCESS);
  253. // 通知帮会频道
  254. CoreDataChanged(GDCNI_PLAYER_BASE_INFO, 0, 0);
  255. }
  256. #endif
  257. #ifdef _SERVER
  258. //-------------------------------------------------------------------------
  259. // 功能:头上是否需要顶找人标志
  260. //-------------------------------------------------------------------------
  261. BOOL KPlayerTong::GetOpenFlag()
  262. {
  263. return (m_nFlag && m_nFigure != enumTONG_FIGURE_MEMBER);
  264. }
  265. #endif
  266. #ifdef _SERVER
  267. //-------------------------------------------------------------------------
  268. // 功能:转发加入帮会申请给对方客户端
  269. //-------------------------------------------------------------------------
  270. BOOL KPlayerTong::TransferAddApply(DWORD dwNpcID)
  271. {
  272. // 已经是帮会成员
  273. if (m_nFlag)
  274. return FALSE;
  275. // 自己的阵营问题
  276. if (Npc[Player[m_nPlayerIndex].m_nIndex].m_CurrentCamp != camp_free ||
  277. Npc[Player[m_nPlayerIndex].m_nIndex].m_Camp != camp_free)
  278. return FALSE;
  279. // 交易过程中
  280. if (Player[m_nPlayerIndex].CheckTrading())
  281. return FALSE;
  282. // 组队不能加入帮会
  283. if (Player[m_nPlayerIndex].m_cTeam.m_nFlag)
  284. return FALSE;
  285. int nTarget = Player[m_nPlayerIndex].FindAroundPlayer(dwNpcID);
  286. if (nTarget == -1)
  287. return FALSE;
  288. if (!Player[nTarget].m_cTong.CheckAcceptAddApplyCondition())
  289. return FALSE;
  290. m_nApplyTo = nTarget;
  291. // 通知客户端
  292. TONG_APPLY_ADD_SYNC sAdd;
  293. sAdd.ProtocolType = s2c_extendtong;
  294. sAdd.m_btMsgId = enumTONG_SYNC_ID_TRANSFER_ADD_APPLY;
  295. sAdd.m_nPlayerIdx = m_nPlayerIndex;
  296. strcpy(sAdd.m_szName, Npc[Player[m_nPlayerIndex].m_nIndex].Name);
  297. sAdd.m_wLength = sizeof(TONG_APPLY_ADD_SYNC) - 1 - sizeof(sAdd.m_szName) + strlen(sAdd.m_szName);
  298. if (g_pServer)
  299. g_pServer->PackDataToClient(Player[nTarget].m_nNetConnectIdx, &sAdd, sAdd.m_wLength + 1);
  300. return TRUE;
  301. }
  302. #endif
  303. #ifdef _SERVER
  304. //-------------------------------------------------------------------------
  305. // 功能:判断是否可以转发别人的加入帮会申请
  306. //-------------------------------------------------------------------------
  307. BOOL KPlayerTong::CheckAcceptAddApplyCondition()
  308. {
  309. if (!m_nFlag || m_nFigure == enumTONG_FIGURE_MEMBER)
  310. return FALSE;
  311. return TRUE;
  312. }
  313. #endif
  314. #ifndef _SERVER
  315. //-------------------------------------------------------------------------
  316. // 功能:是否接受成员 bFlag == TRUE 接受 == FALSE 不接受
  317. //-------------------------------------------------------------------------
  318. void KPlayerTong::AcceptMember(int nPlayerIdx, DWORD dwNameID, BOOL bFlag)
  319. {
  320. if (nPlayerIdx <= 0)
  321. return;
  322. TONG_ACCEPT_MEMBER_COMMAND sAccept;
  323. sAccept.ProtocolType = c2s_extendtong;
  324. sAccept.m_wLength = sizeof(TONG_ACCEPT_MEMBER_COMMAND) - 1;
  325. sAccept.m_btMsgId = enumTONG_COMMAND_ID_ACCEPT_ADD;
  326. sAccept.m_nPlayerIdx = nPlayerIdx;
  327. sAccept.m_dwNameID = dwNameID;
  328. sAccept.m_btFlag = (bFlag != 0);
  329. if (g_pClient)
  330. g_pClient->SendPackToServer(&sAccept, sAccept.m_wLength + 1);
  331. }
  332. #endif
  333. #ifdef _SERVER
  334. //-------------------------------------------------------------------------
  335. // 功能:发消息通知拒绝某人申请
  336. //-------------------------------------------------------------------------
  337. void KPlayerTong::SendRefuseMessage(int nPlayerIdx, DWORD dwNameID)
  338. {
  339. if (nPlayerIdx <= 0 || nPlayerIdx >= MAX_PLAYER)
  340. return;
  341. if (Player[nPlayerIdx].m_cTong.m_nApplyTo != m_nPlayerIndex ||
  342. Player[nPlayerIdx].m_nIndex <= 0 ||
  343. Player[m_nPlayerIndex].m_nIndex <= 0)
  344. return;
  345. if (g_FileName2Id(Npc[Player[nPlayerIdx].m_nIndex].Name) != dwNameID)
  346. return;
  347. int nLength = strlen(Npc[Player[m_nPlayerIndex].m_nIndex].Name);
  348. SHOW_MSG_SYNC sMsg;
  349. sMsg.ProtocolType = s2c_msgshow;
  350. sMsg.m_wMsgID = enumMSG_ID_TONG_REFUSE_ADD;
  351. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID) + nLength;
  352. sMsg.m_lpBuf = new BYTE[sMsg.m_wLength + 1];
  353. memcpy(sMsg.m_lpBuf, &sMsg, sizeof(SHOW_MSG_SYNC) - sizeof(LPVOID));
  354. memcpy((char*)sMsg.m_lpBuf + sizeof(SHOW_MSG_SYNC) - sizeof(LPVOID), Npc[Player[m_nPlayerIndex].m_nIndex].Name, nLength);
  355. if (g_pServer)
  356. g_pServer->PackDataToClient(Player[nPlayerIdx].m_nNetConnectIdx, sMsg.m_lpBuf, sMsg.m_wLength + 1);
  357. }
  358. #endif
  359. void KPlayerTong::GetTongName(char *lpszGetName)
  360. {
  361. if (!lpszGetName)
  362. return;
  363. if (!m_nFlag)
  364. {
  365. lpszGetName[0] = 0;
  366. return;
  367. }
  368. strcpy(lpszGetName, m_szName);
  369. }
  370. #ifdef _SERVER
  371. //-------------------------------------------------------------------------
  372. // 功能:判断别人加入自己帮会条件是否成立
  373. //-------------------------------------------------------------------------
  374. BOOL KPlayerTong::CheckAddCondition(int nPlayerIdx)
  375. {
  376. //--------------------- 自己的条件 -----------------------
  377. if (nPlayerIdx <= 0 || nPlayerIdx >= MAX_PLAYER)
  378. return FALSE;
  379. if (!m_nFlag || m_nFigure == enumTONG_FIGURE_MEMBER)
  380. return FALSE;
  381. //--------------------- 对方的条件 -----------------------
  382. // 是否申请了
  383. if (Player[nPlayerIdx].m_cTong.m_nApplyTo != this->m_nPlayerIndex)
  384. return FALSE;
  385. // 已经是帮会成员
  386. if (Player[nPlayerIdx].m_cTong.m_nFlag)
  387. return FALSE;
  388. // 自己的阵营问题
  389. if (Npc[Player[nPlayerIdx].m_nIndex].m_CurrentCamp != camp_free ||
  390. Npc[Player[nPlayerIdx].m_nIndex].m_Camp != camp_free)
  391. return FALSE;
  392. // 交易过程中
  393. if (Player[nPlayerIdx].CheckTrading())
  394. return FALSE;
  395. // 组队不能加入帮会
  396. if (Player[nPlayerIdx].m_cTeam.m_nFlag)
  397. return FALSE;
  398. return TRUE;
  399. }
  400. #endif
  401. #ifdef _SERVER
  402. //-------------------------------------------------------------------------
  403. // 功能:加入帮会,成为普通帮众
  404. //-------------------------------------------------------------------------
  405. BOOL KPlayerTong::AddTong(int nCamp, char *lpszTongName, char *lpszMasterName, char *lpszTitleName)
  406. {
  407. if (!lpszTongName || !lpszMasterName || !lpszTitleName)
  408. return FALSE;
  409. // 帮会阵营问题
  410. if (nCamp != camp_justice && nCamp != camp_evil && nCamp != camp_balance)
  411. return FALSE;
  412. m_nFlag = 1;
  413. m_nFigure = enumTONG_FIGURE_MEMBER;
  414. m_nCamp = nCamp;
  415. strcpy(this->m_szName, lpszTongName);
  416. strcpy(this->m_szMasterName, lpszMasterName);
  417. strcpy(this->m_szTitle, lpszTitleName);
  418. m_dwTongNameID = g_FileName2Id(m_szName);
  419. Npc[Player[m_nPlayerIndex].m_nIndex].m_Camp = m_nCamp;
  420. Npc[Player[m_nPlayerIndex].m_nIndex].m_CurrentCamp = m_nCamp;
  421. // 通知客户端
  422. TONG_Add_SYNC sAdd;
  423. sAdd.ProtocolType = s2c_extendtong;
  424. sAdd.m_wLength = sizeof(sAdd) - 1;
  425. sAdd.m_btMsgId = enumTONG_SYNC_ID_ADD;
  426. sAdd.m_btCamp = this->m_nCamp;
  427. strcpy(sAdd.m_szTongName, m_szName);
  428. strcpy(sAdd.m_szTitle, m_szTitle);
  429. strcpy(sAdd.m_szMaster, m_szMasterName);
  430. if (g_pServer)
  431. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, &sAdd, sAdd.m_wLength + 1);
  432. return TRUE;
  433. }
  434. #endif
  435. #ifndef _SERVER
  436. //-------------------------------------------------------------------------
  437. // 功能:加入帮会,成为普通帮众
  438. //-------------------------------------------------------------------------
  439. BOOL KPlayerTong::AddTong(int nCamp, char *lpszTongName, char *lpszTitle, char *lpszMaster)
  440. {
  441. if (!lpszTongName || !lpszTongName[0] || strlen(lpszTongName) > defTONG_NAME_MAX_LENGTH)
  442. return FALSE;
  443. // 帮会阵营问题
  444. if (nCamp != camp_justice && nCamp != camp_evil && nCamp != camp_balance)
  445. return FALSE;
  446. m_nFlag = 1;
  447. m_nFigure = enumTONG_FIGURE_MEMBER;
  448. m_nCamp = nCamp;
  449. strcpy(m_szName, lpszTongName);
  450. if (!lpszTitle)
  451. this->m_szTitle[0] = 0;
  452. else
  453. strcpy(m_szTitle, lpszTitle);
  454. if (!lpszMaster)
  455. this->m_szMasterName[0] = 0;
  456. else
  457. strcpy(m_szMasterName, lpszMaster);
  458. m_dwTongNameID = g_FileName2Id(m_szName);
  459. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_Camp = m_nCamp;
  460. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentCamp = m_nCamp;
  461. defFuncShowNormalMsg(MSG_TONG_ADD_SUCCESS);
  462. return TRUE;
  463. }
  464. #endif
  465. #ifndef _SERVER
  466. //-------------------------------------------------------------------------
  467. // 功能:申请任命
  468. //-------------------------------------------------------------------------
  469. BOOL KPlayerTong::ApplyInstate(int nCurFigure, int nCurPos, int nNewFigure, int nNewPos, char *lpszName)
  470. {
  471. if (!lpszName)
  472. return FALSE;
  473. if (!m_nFlag)
  474. return FALSE;
  475. if (nCurFigure < 0 || nCurFigure >= enumTONG_FIGURE_NUM ||
  476. nNewFigure < 0 || nNewFigure >= enumTONG_FIGURE_NUM)
  477. return FALSE;
  478. if (nCurPos < 0 || nNewPos < 0)
  479. return FALSE;
  480. if (nCurFigure == nNewFigure && nCurPos == nNewPos)
  481. return FALSE;
  482. switch (m_nFigure)
  483. {
  484. case enumTONG_FIGURE_MEMBER:
  485. // 帮众没有任命权力
  486. return FALSE;
  487. case enumTONG_FIGURE_MANAGER:
  488. // 队长没有任命权力
  489. return FALSE;
  490. case enumTONG_FIGURE_DIRECTOR:
  491. // 长老只有对队长、帮众的任命权力
  492. if ((nCurFigure != enumTONG_FIGURE_MANAGER && nCurFigure != enumTONG_FIGURE_MEMBER) ||
  493. (nNewFigure != enumTONG_FIGURE_MANAGER && nNewFigure != enumTONG_FIGURE_MEMBER))
  494. return FALSE;
  495. if (nCurFigure == enumTONG_FIGURE_MANAGER && nCurPos >= defTONG_MAX_MANAGER)
  496. return FALSE;
  497. if (nNewFigure == enumTONG_FIGURE_MANAGER && nNewPos >= defTONG_MAX_MANAGER)
  498. return FALSE;
  499. break;
  500. case enumTONG_FIGURE_MASTER:
  501. // 帮主有对长老、队长、帮众的任命权力
  502. if (nCurFigure == enumTONG_FIGURE_MASTER || nNewFigure == enumTONG_FIGURE_MASTER)
  503. return FALSE;
  504. if (nCurFigure == enumTONG_FIGURE_MANAGER && nCurPos >= defTONG_MAX_MANAGER)
  505. return FALSE;
  506. if (nCurFigure == enumTONG_FIGURE_DIRECTOR && nCurPos >= defTONG_MAX_DIRECTOR)
  507. return FALSE;
  508. if (nNewFigure == enumTONG_FIGURE_MANAGER && nNewPos >= defTONG_MAX_MANAGER)
  509. return FALSE;
  510. if (nNewFigure == enumTONG_FIGURE_DIRECTOR && nNewPos >= defTONG_MAX_DIRECTOR)
  511. return FALSE;
  512. break;
  513. default:
  514. return FALSE;
  515. }
  516. TONG_APPLY_INSTATE_COMMAND sApply;
  517. if (strlen(lpszName) >= sizeof(sApply.m_szName))
  518. return FALSE;
  519. sApply.ProtocolType = c2s_extendtong;
  520. sApply.m_btMsgId = enumTONG_COMMAND_ID_APPLY_INSTATE;
  521. sApply.m_dwTongNameID = g_FileName2Id(this->m_szName);
  522. sApply.m_btCurFigure = nCurFigure;
  523. sApply.m_btCurPos = nCurPos;
  524. sApply.m_btNewFigure = nNewFigure;
  525. sApply.m_btNewPos = nNewPos;
  526. memset(sApply.m_szName, 0, sizeof(sApply.m_szName));
  527. strcpy(sApply.m_szName, lpszName);
  528. sApply.m_wLength = sizeof(sApply) - 1;
  529. if (g_pClient)
  530. g_pClient->SendPackToServer(&sApply, sApply.m_wLength + 1);
  531. return TRUE;
  532. }
  533. #endif
  534. #ifndef _SERVER
  535. //-------------------------------------------------------------------------
  536. // 功能:申请踢人
  537. //-------------------------------------------------------------------------
  538. BOOL KPlayerTong::ApplyKick(int nCurFigure, int nCurPos, char *lpszName)
  539. {
  540. if (!lpszName || !lpszName[0] || strlen(lpszName) >= 32)
  541. return FALSE;
  542. if (!m_nFlag)
  543. return FALSE;
  544. if (m_nFigure != enumTONG_FIGURE_MASTER && m_nFigure != enumTONG_FIGURE_DIRECTOR)
  545. return FALSE;
  546. if (nCurFigure != enumTONG_FIGURE_MANAGER && nCurFigure != enumTONG_FIGURE_MEMBER)
  547. return FALSE;
  548. if (nCurFigure == enumTONG_FIGURE_MANAGER && (nCurPos < 0 || nCurPos >= defTONG_MAX_MANAGER))
  549. return FALSE;
  550. TONG_APPLY_KICK_COMMAND sKick;
  551. sKick.ProtocolType = c2s_extendtong;
  552. sKick.m_wLength = sizeof(sKick) - 1;
  553. sKick.m_btMsgId = enumTONG_COMMAND_ID_APPLY_KICK;
  554. sKick.m_btFigure = nCurFigure;
  555. sKick.m_btPos = nCurPos;
  556. sKick.m_dwTongNameID = g_FileName2Id(this->m_szName);
  557. strcpy(sKick.m_szName, lpszName);
  558. if (g_pClient)
  559. g_pClient->SendPackToServer(&sKick, sKick.m_wLength + 1);
  560. return TRUE;
  561. }
  562. #endif
  563. #ifndef _SERVER
  564. //-------------------------------------------------------------------------
  565. // 功能:申请传位
  566. //-------------------------------------------------------------------------
  567. BOOL KPlayerTong::ApplyChangeMaster(int nCurFigure, int nPos, char *lpszName)
  568. {
  569. if (!lpszName || !lpszName[0] || strlen(lpszName) >= 32)
  570. return FALSE;
  571. if (!m_nFlag)
  572. return FALSE;
  573. if (m_nFigure != enumTONG_FIGURE_MASTER)
  574. return FALSE;
  575. TONG_APPLY_CHANGE_MASTER_COMMAND sChange;
  576. sChange.ProtocolType = c2s_extendtong;
  577. sChange.m_wLength = sizeof(sChange) - 1;
  578. sChange.m_btMsgId = enumTONG_COMMAND_ID_APPLY_CHANGE_MASTER;
  579. sChange.m_dwTongNameID = g_FileName2Id(this->m_szName);
  580. sChange.m_btFigure = nCurFigure;
  581. sChange.m_btPos = nPos;
  582. strcpy(sChange.m_szName, lpszName);
  583. if (g_pClient)
  584. g_pClient->SendPackToServer(&sChange, sChange.m_wLength + 1);
  585. return TRUE;
  586. }
  587. #endif
  588. #ifndef _SERVER
  589. //-------------------------------------------------------------------------
  590. // 功能:申请离开帮会
  591. //-------------------------------------------------------------------------
  592. BOOL KPlayerTong::ApplyLeave()
  593. {
  594. if (!m_nFlag)
  595. return FALSE;
  596. if (m_nFigure == enumTONG_FIGURE_MASTER)
  597. {
  598. defFuncShowNormalMsg(MSG_TONG_CANNOT_LEAVE1);
  599. return FALSE;
  600. }
  601. if (m_nFigure == enumTONG_FIGURE_DIRECTOR)
  602. {
  603. defFuncShowNormalMsg(MSG_TONG_CANNOT_LEAVE2);
  604. return FALSE;
  605. }
  606. TONG_APPLY_LEAVE_COMMAND sLeave;
  607. sLeave.ProtocolType = c2s_extendtong;
  608. sLeave.m_wLength = sizeof(sLeave) - 1;
  609. sLeave.m_btMsgId = enumTONG_COMMAND_ID_APPLY_LEAVE;
  610. sLeave.m_btFigure = m_nFigure;
  611. sLeave.m_btPos = 0;
  612. sLeave.m_dwTongNameID = g_FileName2Id(this->m_szName);
  613. strcpy(sLeave.m_szName, Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name);
  614. if (g_pClient)
  615. g_pClient->SendPackToServer(&sLeave, sLeave.m_wLength + 1);
  616. return TRUE;
  617. }
  618. #endif
  619. #ifndef _SERVER
  620. //-------------------------------------------------------------------------
  621. // 功能:申请获得帮会信息
  622. //-------------------------------------------------------------------------
  623. BOOL KPlayerTong::ApplyInfo(int nInfoID, int nParam1, int nParam2, int nParam3, char *lpszName/*=NULL*/)
  624. {
  625. if (nInfoID < 0 || nInfoID >= enumTONG_APPLY_INFO_ID_NUM)
  626. return FALSE;
  627. TONG_APPLY_INFO_COMMAND sInfo;
  628. sInfo.ProtocolType = c2s_extendtong;
  629. sInfo.m_btMsgId = enumTONG_COMMAND_ID_APPLY_INFO;
  630. sInfo.m_btInfoID = nInfoID;
  631. sInfo.m_nParam1 = nParam1;
  632. sInfo.m_nParam2 = nParam2;
  633. sInfo.m_nParam3 = nParam3;
  634. switch (nInfoID)
  635. {
  636. case enumTONG_APPLY_INFO_ID_SELF:
  637. sInfo.m_wLength = sizeof(sInfo) - 1 - sizeof(sInfo.m_szBuf);
  638. if (g_pClient)
  639. g_pClient->SendPackToServer(&sInfo, sInfo.m_wLength + 1);
  640. break;
  641. case enumTONG_APPLY_INFO_ID_MASTER:
  642. break;
  643. case enumTONG_APPLY_INFO_ID_DIRECTOR:
  644. break;
  645. case enumTONG_APPLY_INFO_ID_MANAGER:
  646. if (!m_nFlag)
  647. break;
  648. if (this->m_nFigure != enumTONG_FIGURE_MASTER &&
  649. this->m_nFigure != enumTONG_FIGURE_DIRECTOR)
  650. break;
  651. sInfo.m_wLength = sizeof(sInfo) - 1 - sizeof(sInfo.m_szBuf);
  652. if (g_pClient)
  653. g_pClient->SendPackToServer(&sInfo, sInfo.m_wLength + 1);
  654. break;
  655. case enumTONG_APPLY_INFO_ID_MEMBER:
  656. if (!m_nFlag)
  657. break;
  658. if (this->m_nFigure != enumTONG_FIGURE_MASTER &&
  659. this->m_nFigure != enumTONG_FIGURE_DIRECTOR)
  660. break;
  661. sInfo.m_wLength = sizeof(sInfo) - 1 - sizeof(sInfo.m_szBuf);
  662. if (g_pClient)
  663. g_pClient->SendPackToServer(&sInfo, sInfo.m_wLength + 1);
  664. break;
  665. case enumTONG_APPLY_INFO_ID_ONE:
  666. if (!lpszName || !lpszName[0])
  667. break;
  668. if (strlen(lpszName) >= 32)
  669. break;
  670. strcpy(sInfo.m_szBuf, lpszName);
  671. sInfo.m_wLength = sizeof(sInfo) - 1 - sizeof(sInfo.m_szBuf) + strlen(lpszName);
  672. if (g_pClient)
  673. g_pClient->SendPackToServer(&sInfo, sInfo.m_wLength + 1);
  674. break;
  675. case enumTONG_APPLY_INFO_ID_TONG_HEAD:
  676. if (nParam1 <= 0 || nParam1 >= MAX_NPC)
  677. break;
  678. if (nParam1 != Player[CLIENT_PLAYER_INDEX].m_nIndex && Npc[nParam1].m_nTongFlag == 0)
  679. break;
  680. sInfo.m_nParam1 = Npc[nParam1].m_dwID;
  681. sInfo.m_wLength = sizeof(sInfo) - 1 - sizeof(sInfo.m_szBuf);
  682. if (g_pClient)
  683. g_pClient->SendPackToServer(&sInfo, sInfo.m_wLength + 1);
  684. break;
  685. }
  686. return TRUE;
  687. }
  688. #endif
  689. DWORD KPlayerTong::GetTongNameID()
  690. {
  691. return (m_nFlag ? m_dwTongNameID : 0);
  692. // if (!m_nFlag)
  693. // return 0;
  694. // if (m_szName[0])
  695. // return 0;
  696. // return g_FileName2Id(m_szName);
  697. }
  698. //-------------------------------------------------------------------------
  699. // 功能:是否有权力查询队长信息
  700. //-------------------------------------------------------------------------
  701. BOOL KPlayerTong::CanGetManagerInfo(DWORD dwTongNameID)
  702. {
  703. if (!m_nFlag)
  704. return FALSE;
  705. if (dwTongNameID != g_FileName2Id(this->m_szName))
  706. return FALSE;
  707. if (m_nFigure == enumTONG_FIGURE_MASTER || m_nFigure == enumTONG_FIGURE_DIRECTOR)
  708. return TRUE;
  709. return FALSE;
  710. }
  711. //-------------------------------------------------------------------------
  712. // 功能:是否有权力查询帮众信息
  713. //-------------------------------------------------------------------------
  714. BOOL KPlayerTong::CanGetMemberInfo(DWORD dwTongNameID)
  715. {
  716. if (!m_nFlag)
  717. return FALSE;
  718. if (dwTongNameID != g_FileName2Id(this->m_szName))
  719. return FALSE;
  720. if (m_nFigure == enumTONG_FIGURE_MASTER || m_nFigure == enumTONG_FIGURE_DIRECTOR)
  721. return TRUE;
  722. return FALSE;
  723. }
  724. #ifdef _SERVER
  725. //-------------------------------------------------------------------------
  726. // 功能:给客户端发送自己在帮会中的信息
  727. //-------------------------------------------------------------------------
  728. void KPlayerTong::SendSelfInfo()
  729. {
  730. TONG_SELF_INFO_SYNC sInfo;
  731. sInfo.ProtocolType = s2c_extendtong;
  732. sInfo.m_wLength = sizeof(sInfo) - 1;
  733. sInfo.m_btMsgId = enumTONG_SYNC_ID_SELF_INFO;
  734. sInfo.m_btJoinFlag = this->m_nFlag;
  735. sInfo.m_btFigure = this->m_nFigure;
  736. sInfo.m_btCamp = this->m_nCamp;
  737. strcpy(sInfo.m_szMaster, this->m_szMasterName);
  738. strcpy(sInfo.m_szTitle, this->m_szTitle);
  739. strcpy(sInfo.m_szTongName, this->m_szName);
  740. if (g_pServer)
  741. g_pServer->PackDataToClient(Player[this->m_nPlayerIndex].m_nNetConnectIdx, &sInfo, sInfo.m_wLength + 1);
  742. }
  743. #endif
  744. #ifndef _SERVER
  745. //-------------------------------------------------------------------------
  746. // 功能:设定自身帮会信息
  747. //-------------------------------------------------------------------------
  748. void KPlayerTong::SetSelfInfo(TONG_SELF_INFO_SYNC *pInfo)
  749. {
  750. if (pInfo->m_btJoinFlag == 0)
  751. {
  752. if (m_nFlag)
  753. {
  754. KUiGameObjectWithName sUi;
  755. strcpy(sUi.szName, Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name);
  756. sUi.nData = TONG_ACTION_LEAVE;
  757. sUi.nParam = m_nFigure;
  758. sUi.uParam = 0;
  759. sUi.szString[0] = 0;
  760. CoreDataChanged(GDCNI_TONG_ACTION_RESULT, (unsigned int)&sUi, 1);
  761. // 被踢出帮会
  762. // defFuncShowNormalMsg("您被踢出帮会!");
  763. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_Camp = camp_free;
  764. if (!Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag)
  765. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentCamp = camp_free;
  766. }
  767. Clear();
  768. CoreDataChanged(GDCNI_PLAYER_BASE_INFO, 0, 0);
  769. return;
  770. }
  771. if (m_nFlag == 1 && m_nFigure != pInfo->m_btFigure)
  772. {
  773. // 被任命
  774. defFuncShowNormalMsg("您在帮会中的职位发生了变化!");
  775. }
  776. this->m_nFlag = 1;
  777. this->m_nFigure = pInfo->m_btFigure;
  778. this->m_nCamp = pInfo->m_btCamp;
  779. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_Camp = m_nCamp;
  780. if (Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag == 0)
  781. Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_CurrentCamp = m_nCamp;
  782. memcpy(this->m_szMasterName, pInfo->m_szMaster, sizeof(pInfo->m_szMaster));
  783. memcpy(this->m_szName, pInfo->m_szTongName, sizeof(pInfo->m_szTongName));
  784. memcpy(this->m_szTitle, pInfo->m_szTitle, sizeof(pInfo->m_szTitle));
  785. m_dwTongNameID = g_FileName2Id(m_szName);
  786. CoreDataChanged(GDCNI_PLAYER_BASE_INFO, 0, 0);
  787. }
  788. #endif
  789. #ifdef _SERVER
  790. //-------------------------------------------------------------------------
  791. // 功能:检测是否有任命权利
  792. //-------------------------------------------------------------------------
  793. BOOL KPlayerTong::CheckInstatePower(TONG_APPLY_INSTATE_COMMAND *pApply)
  794. {
  795. if (!pApply)
  796. return FALSE;
  797. if (pApply->m_wLength <= sizeof(TONG_APPLY_INSTATE_COMMAND) - 1 - sizeof(pApply->m_szName))
  798. return FALSE;
  799. if (!m_nFlag || (m_nFigure != enumTONG_FIGURE_MASTER && m_nFigure != enumTONG_FIGURE_DIRECTOR))
  800. return FALSE;
  801. if (pApply->m_dwTongNameID != g_FileName2Id(m_szName))
  802. return FALSE;
  803. if (pApply->m_btCurFigure == pApply->m_btNewFigure && pApply->m_btCurPos == pApply->m_btNewPos)
  804. return FALSE;
  805. char szName[32];
  806. memcpy(szName, pApply->m_szName, sizeof(pApply->m_szName));
  807. szName[31] = 0;
  808. if (strlen(szName) >= 31)
  809. return FALSE;
  810. if (m_nFigure == enumTONG_FIGURE_MASTER)
  811. {
  812. if (pApply->m_btCurFigure == enumTONG_FIGURE_DIRECTOR)
  813. {
  814. if (pApply->m_btCurPos >= defTONG_MAX_DIRECTOR)
  815. return FALSE;
  816. }
  817. else if (pApply->m_btCurFigure == enumTONG_FIGURE_MANAGER)
  818. {
  819. if (pApply->m_btCurPos >= defTONG_MAX_MANAGER)
  820. return FALSE;
  821. }
  822. else if (pApply->m_btCurFigure == enumTONG_FIGURE_MEMBER)
  823. {
  824. }
  825. else
  826. {
  827. return FALSE;
  828. }
  829. if (pApply->m_btNewFigure == enumTONG_FIGURE_DIRECTOR)
  830. {
  831. if (pApply->m_btNewPos >= defTONG_MAX_DIRECTOR)
  832. return FALSE;
  833. }
  834. else if (pApply->m_btNewFigure == enumTONG_FIGURE_MANAGER)
  835. {
  836. if (pApply->m_btNewPos >= defTONG_MAX_MANAGER)
  837. return FALSE;
  838. }
  839. else if (pApply->m_btNewFigure == enumTONG_FIGURE_MEMBER)
  840. {
  841. }
  842. else
  843. {
  844. return FALSE;
  845. }
  846. }
  847. else // if (m_nFigure == enumTONG_FIGURE_DIRECTOR)
  848. {
  849. if (pApply->m_btCurFigure == enumTONG_FIGURE_MANAGER)
  850. {
  851. if (pApply->m_btCurPos >= defTONG_MAX_MANAGER)
  852. return FALSE;
  853. }
  854. else if (pApply->m_btCurFigure == enumTONG_FIGURE_MEMBER)
  855. {
  856. }
  857. else
  858. {
  859. return FALSE;
  860. }
  861. if (pApply->m_btNewFigure == enumTONG_FIGURE_MANAGER)
  862. {
  863. if (pApply->m_btNewPos >= defTONG_MAX_MANAGER)
  864. return FALSE;
  865. }
  866. else if (pApply->m_btNewFigure == enumTONG_FIGURE_MEMBER)
  867. {
  868. }
  869. else
  870. {
  871. return FALSE;
  872. }
  873. }
  874. return TRUE;
  875. }
  876. #endif
  877. #ifdef _SERVER
  878. //-------------------------------------------------------------------------
  879. // 功能:检测是否有踢人权利
  880. //-------------------------------------------------------------------------
  881. BOOL KPlayerTong::CheckKickPower(TONG_APPLY_KICK_COMMAND *pKick)
  882. {
  883. if (!pKick)
  884. return FALSE;
  885. if (pKick->m_wLength + 1 != sizeof(TONG_APPLY_KICK_COMMAND))
  886. return FALSE;
  887. if (!m_nFlag || (m_nFigure != enumTONG_FIGURE_MASTER && m_nFigure != enumTONG_FIGURE_DIRECTOR))
  888. return FALSE;
  889. if (pKick->m_dwTongNameID != g_FileName2Id(m_szName))
  890. return FALSE;
  891. if (pKick->m_btFigure == enumTONG_FIGURE_MANAGER)
  892. {
  893. if (pKick->m_btPos >= defTONG_MAX_MANAGER)
  894. return FALSE;
  895. }
  896. else if (pKick->m_btFigure == enumTONG_FIGURE_MEMBER)
  897. {
  898. }
  899. else
  900. return FALSE;
  901. return TRUE;
  902. }
  903. #endif
  904. #ifdef _SERVER
  905. //-------------------------------------------------------------------------
  906. // 功能:被任命
  907. //-------------------------------------------------------------------------
  908. void KPlayerTong::BeInstated(STONG_SERVER_TO_CORE_BE_INSTATED *pSync)
  909. {
  910. this->m_nFlag = 1;
  911. this->m_nFigure = pSync->m_btFigure;
  912. strcpy(m_szTitle, pSync->m_szTitle);
  913. SendSelfInfo();
  914. }
  915. #endif
  916. #ifdef _SERVER
  917. //-------------------------------------------------------------------------
  918. // 功能:被踢出帮会
  919. //-------------------------------------------------------------------------
  920. void KPlayerTong::BeKicked(STONG_SERVER_TO_CORE_BE_KICKED *pSync)
  921. {
  922. Clear();
  923. Npc[Player[m_nPlayerIndex].m_nIndex].m_Camp = camp_free;
  924. if (!Player[this->m_nPlayerIndex].m_cTeam.m_nFlag)
  925. Npc[Player[m_nPlayerIndex].m_nIndex].m_CurrentCamp = camp_free;
  926. SendSelfInfo();
  927. SHOW_MSG_SYNC sMsg;
  928. // 被踢出帮会
  929. sMsg.ProtocolType = s2c_msgshow;
  930. sMsg.m_wMsgID = enumMSG_ID_TONG_BE_KICK;
  931. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  932. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  933. }
  934. #endif
  935. #ifdef _SERVER
  936. //-------------------------------------------------------------------------
  937. // 功能:检测是否有离开权利
  938. //-------------------------------------------------------------------------
  939. BOOL KPlayerTong::CheckLeavePower(TONG_APPLY_LEAVE_COMMAND *pLeave)
  940. {
  941. if (!pLeave)
  942. return FALSE;
  943. if (pLeave->m_wLength + 1 != sizeof(TONG_APPLY_LEAVE_COMMAND))
  944. return FALSE;
  945. if (!m_nFlag || m_nFigure == enumTONG_FIGURE_MASTER || m_nFigure == enumTONG_FIGURE_DIRECTOR)
  946. return FALSE;
  947. if (pLeave->m_dwTongNameID != g_FileName2Id(m_szName))
  948. return FALSE;
  949. return TRUE;
  950. }
  951. #endif
  952. #ifdef _SERVER
  953. //-------------------------------------------------------------------------
  954. // 功能:离开帮会
  955. //-------------------------------------------------------------------------
  956. void KPlayerTong::Leave(STONG_SERVER_TO_CORE_LEAVE *pLeave)
  957. {
  958. if (strcmp(pLeave->m_szName, Npc[Player[m_nPlayerIndex].m_nIndex].Name) != 0)
  959. return;
  960. if (pLeave->m_bSuccessFlag)
  961. {
  962. Clear();
  963. Npc[Player[m_nPlayerIndex].m_nIndex].m_Camp = camp_free;
  964. if (!Player[this->m_nPlayerIndex].m_cTeam.m_nFlag)
  965. Npc[Player[m_nPlayerIndex].m_nIndex].m_CurrentCamp = camp_free;
  966. SendSelfInfo();
  967. SHOW_MSG_SYNC sMsg;
  968. // 离开帮会成功
  969. sMsg.ProtocolType = s2c_msgshow;
  970. sMsg.m_wMsgID = enumMSG_ID_TONG_LEAVE_SUCCESS;
  971. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  972. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  973. }
  974. else
  975. {
  976. SendSelfInfo();
  977. SHOW_MSG_SYNC sMsg;
  978. // 离开帮会失败
  979. sMsg.ProtocolType = s2c_msgshow;
  980. sMsg.m_wMsgID = enumMSG_ID_TONG_LEAVE_FAIL;
  981. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  982. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  983. }
  984. }
  985. #endif
  986. #ifdef _SERVER
  987. //-------------------------------------------------------------------------
  988. // 功能:检测是否有权利换帮主
  989. //-------------------------------------------------------------------------
  990. BOOL KPlayerTong::CheckChangeMasterPower(TONG_APPLY_CHANGE_MASTER_COMMAND *pChange)
  991. {
  992. if (!pChange)
  993. return FALSE;
  994. if (pChange->m_wLength + 1 != sizeof(TONG_APPLY_CHANGE_MASTER_COMMAND))
  995. return FALSE;
  996. if (!m_nFlag || m_nFigure != enumTONG_FIGURE_MASTER)
  997. return FALSE;
  998. if (pChange->m_dwTongNameID != g_FileName2Id(m_szName))
  999. return FALSE;
  1000. char szName[32];
  1001. memcpy(szName, pChange->m_szName, sizeof(pChange->m_szName));
  1002. szName[31] = 0;
  1003. if (strlen(szName) >= 31)
  1004. return FALSE;
  1005. return TRUE;
  1006. }
  1007. #endif
  1008. #ifdef _SERVER
  1009. //-------------------------------------------------------------------------
  1010. // 功能:检测是否有能力接受传位
  1011. //-------------------------------------------------------------------------
  1012. BOOL KPlayerTong::CheckGetMasterPower(STONG_SERVER_TO_CORE_CHECK_GET_MASTER_POWER *pCheck)
  1013. {
  1014. if (!pCheck)
  1015. return FALSE;
  1016. if (!m_nFlag || m_nFigure == enumTONG_FIGURE_MASTER)
  1017. return FALSE;
  1018. if (pCheck->m_dwTongNameID != g_FileName2Id(m_szName))
  1019. return FALSE;
  1020. // if (m_nFigure != pCheck->m_btFigure)
  1021. // return FALSE;
  1022. if (strcmp(pCheck->m_szName, Npc[Player[m_nPlayerIndex].m_nIndex].Name) != 0)
  1023. return FALSE;
  1024. // 等级问题
  1025. if (Npc[Player[m_nPlayerIndex].m_nIndex].m_Level < PlayerSet.m_sTongParam.m_nLevel || 
  1026. (int)Player[m_nPlayerIndex].m_dwLeadLevel < PlayerSet.m_sTongParam.m_nLeadLevel)
  1027. return FALSE;
  1028. return TRUE;
  1029. }
  1030. #endif
  1031. #ifdef _SERVER
  1032. //-------------------------------------------------------------------------
  1033. // 功能:传位导致身份改变
  1034. //-------------------------------------------------------------------------
  1035. void KPlayerTong::ChangeAs(STONG_SERVER_TO_CORE_CHANGE_AS *pAs)
  1036. {
  1037. if (!pAs)
  1038. return;
  1039. if (!m_nFlag)
  1040. return;
  1041. if (pAs->m_dwTongNameID != g_FileName2Id(m_szName))
  1042. return;
  1043. m_nFigure = pAs->m_btFigure;
  1044. strcpy(m_szTitle, pAs->m_szTitle);
  1045. strcpy(this->m_szMasterName, pAs->m_szName);
  1046. this->SendSelfInfo();
  1047. SHOW_MSG_SYNC sMsg;
  1048. sMsg.ProtocolType = s2c_msgshow;
  1049. if (m_nFigure == enumTONG_FIGURE_MASTER)
  1050. sMsg.m_wMsgID = enumMSG_ID_TONG_CHANGE_AS_MASTER;
  1051. else
  1052. sMsg.m_wMsgID = enumMSG_ID_TONG_CHANGE_AS_MEMBER;
  1053. sMsg.m_wLength = sizeof(SHOW_MSG_SYNC) - 1 - sizeof(LPVOID);
  1054. g_pServer->PackDataToClient(Player[m_nPlayerIndex].m_nNetConnectIdx, &sMsg, sMsg.m_wLength + 1);
  1055. return;
  1056. }
  1057. #endif
  1058. #ifdef _SERVER
  1059. //-------------------------------------------------------------------------
  1060. // 功能:换帮主
  1061. //-------------------------------------------------------------------------
  1062. void KPlayerTong::ChangeMaster(char *lpszMaster)
  1063. {
  1064. if (!lpszMaster || !lpszMaster[0])
  1065. return;
  1066. if (strlen(lpszMaster) >= sizeof(this->m_szMasterName))
  1067. return;
  1068. strcpy(m_szMasterName, lpszMaster);
  1069. this->SendSelfInfo();
  1070. }
  1071. #endif
  1072. #ifdef _SERVER
  1073. //-------------------------------------------------------------------------
  1074. // 功能:登陆时候获得帮会信息
  1075. //-------------------------------------------------------------------------
  1076. void KPlayerTong::Login(STONG_SERVER_TO_CORE_LOGIN *pLogin)
  1077. {
  1078. if (strcmp(Npc[Player[this->m_nPlayerIndex].m_nIndex].Name, pLogin->m_szName) != 0)
  1079. return;
  1080. if (pLogin->m_nFlag == 0)
  1081. {
  1082. Clear();
  1083. Npc[Player[m_nPlayerIndex].m_nIndex].m_Camp = camp_free;
  1084. if (!Player[m_nPlayerIndex].m_cTeam.m_nFlag)
  1085. Npc[Player[m_nPlayerIndex].m_nIndex].m_CurrentCamp = m_nCamp;
  1086. this->SendSelfInfo();
  1087. return;
  1088. }
  1089. m_nFlag = 1;
  1090. m_nFigure = pLogin->m_nFigure;
  1091. m_nCamp = pLogin->m_nCamp;
  1092. m_dwTongNameID = g_FileName2Id(pLogin->m_szTongName);
  1093. m_nApplyTo = 0;
  1094. strcpy(m_szName, pLogin->m_szTongName);
  1095. strcpy(m_szTitle, pLogin->m_szTitle);
  1096. strcpy(m_szMasterName, pLogin->m_szMaster);
  1097. Npc[Player[m_nPlayerIndex].m_nIndex].m_Camp = m_nCamp;
  1098. if (!Player[m_nPlayerIndex].m_cTeam.m_nFlag)
  1099. Npc[Player[m_nPlayerIndex].m_nIndex].m_CurrentCamp = m_nCamp;
  1100. this->SendSelfInfo();
  1101. }
  1102. #endif
  1103. #ifndef _SERVER
  1104. void    KPlayerTong::OpenCreateInterface()
  1105. {
  1106. CoreDataChanged(GDCNI_OPEN_TONG_CREATE_SHEET, 1, 0);
  1107. }
  1108. #endif