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

模拟服务器

开发平台:

C/C++

  1. //---------------------------------------------------------------------------
  2. // Sword3 Engine (c) 2002 by Kingsoft
  3. //
  4. // File: KPlayerChat.cpp
  5. // Date: 2002.10.05
  6. // Code: 边城浪子
  7. // Desc: PlayerChat Class
  8. //---------------------------------------------------------------------------
  9. #ifdef _STANDALONE
  10. #include <string>
  11. #endif
  12. #include "KCore.h"
  13. #ifdef _SERVER
  14. //#include "KNetServer.h"
  15. //#include "../MultiServer/Heaven/Interface/iServer.h"
  16. #include "KGMCommand.h"
  17. #else
  18. //#include "KNetClient.h"
  19. #include "../../Headers/IClient.h"
  20. #include "CoreShell.h"
  21. #endif
  22. #include "KNpc.h"
  23. #include "KNpcSet.h"
  24. #include "KSubWorld.h"
  25. #include "KPlayer.h"
  26. #include "KPlayerSet.h"
  27. #include "KPlayerTeam.h"
  28. #include "KPlayerChat.h"
  29. #include "MsgGenreDef.h"
  30. #include "CoreUseNameDef.h"
  31. #include "malloc.h"
  32. #ifdef _SERVER
  33. #include "KNewProtocolProcess.h"
  34. #endif
  35. #include "KTongProtocol.h"
  36. #define CHAT_TEAM_DEFAULT_NAME "我的好友"
  37. DWORD g_dwChannelOr[CHAT_CUR_CHANNEL_NUM] =
  38. {
  39. 0x00000000, // CHAT_CUR_CHANNEL_NONE
  40. 0x00000001, // CHAT_CUR_CHANNEL_ALL
  41. 0x00000002, // CHAT_CUR_CHANNEL_SCREEN
  42. 0x00000004, // CHAT_CUR_CHANNEL_SINGLE
  43. 0x00000008, // CHAT_CUR_CHANNEL_TEAM
  44. 0x00000010, // CHAT_CUR_CHANNEL_FACTION
  45. 0x00000020, // CHAT_CUR_CHANNEL_TONG
  46. 0x00000040, // CHAT_CUR_CHANNEL_SCREENSINGLE
  47. 0x00000080, // CHAT_CUR_CHANNEL_SYSTEM
  48. };
  49. DWORD g_dwChannelAnd[CHAT_CUR_CHANNEL_NUM] =
  50. {
  51. 0xffffffff, // CHAT_CUR_CHANNEL_NONE
  52. 0xfffffffe, // CHAT_CUR_CHANNEL_ALL
  53. 0xfffffffd, // CHAT_CUR_CHANNEL_SCREEN
  54. 0xfffffffb, // CHAT_CUR_CHANNEL_SINGLE
  55. 0xfffffff7, // CHAT_CUR_CHANNEL_TEAM
  56. 0xffffffef, // CHAT_CUR_CHANNEL_FACTION
  57. 0xffffffdf, // CHAT_CUR_CHANNEL_TONG
  58. 0xffffffbf, // CHAT_CUR_CHANNEL_SCREENSINGLE
  59. 0xffffff7f, // CHAT_CUR_CHANNEL_SYSTEM
  60. };
  61. //---------------------------------------------------------------------------
  62. // 功能:清空
  63. //---------------------------------------------------------------------------
  64. void KPlayerChat::Release()
  65. {
  66. #ifndef _SERVER
  67. m_btIniLoadFlag = FALSE;
  68. m_nCurChannel = CHAT_CUR_CHANNEL_SCREEN;
  69. CChatApplyListNode *pNode;
  70. pNode = (CChatApplyListNode*)m_cApplyAddList.GetHead();
  71. while (pNode)
  72. {
  73. m_cApplyAddList.RemoveHead();
  74. delete pNode;
  75. pNode = (CChatApplyListNode*)m_cApplyAddList.GetHead();
  76. }
  77. m_nLoginGetFirstOneFriendFlag = 0;
  78. #else
  79. memset(m_nAddFriendList, 0, sizeof(this->m_nAddFriendList));
  80. m_nListPos = 0;
  81. m_nSyncState = 0;
  82. m_pStateSendPos = NULL;
  83. m_nTimer = CHAT_SPEED;
  84. #endif
  85. m_dwTakeChannel = 0;
  86. this->SetTakeChannel(g_dwChannelOr[CHAT_CUR_CHANNEL_SCREEN]);
  87. m_dwTargetID = 0;
  88. m_nTargetIdx = 0;
  89. for (int i = 0; i < MAX_FRIEND_TEAM; i++)
  90. {
  91. m_cFriendTeam[i].Release();
  92. }
  93. strcpy(m_cFriendTeam[0].m_szTeamName, CHAT_TEAM_DEFAULT_NAME);
  94. }
  95. BOOL KPlayerChat::CheckExist(DWORD dwID)
  96. {
  97. CChatFriend *pNode;
  98. for (int i = 0; i < MAX_FRIEND_TEAM; i++)
  99. {
  100. if (m_cFriendTeam[i].m_nFriendNo <= 0)
  101. continue;
  102. pNode = (CChatFriend*)m_cFriendTeam[i].m_cEveryOne.GetHead();
  103. while (pNode)
  104. {
  105. if (pNode->m_dwID == dwID)
  106. return TRUE;
  107. pNode = (CChatFriend*)pNode->GetNext();
  108. }
  109. }
  110. return FALSE;
  111. }
  112. BOOL KPlayerChat::CheckExist(char *lpszName)
  113. {
  114. if (!lpszName || !lpszName[0])
  115. return FALSE;
  116. CChatFriend *pNode;
  117. for (int i = 0; i < MAX_FRIEND_TEAM; i++)
  118. {
  119. if (m_cFriendTeam[i].m_nFriendNo <= 0)
  120. continue;
  121. pNode = (CChatFriend*)m_cFriendTeam[i].m_cEveryOne.GetHead();
  122. while (pNode)
  123. {
  124. if (strcmp(lpszName, pNode->m_szName) == 0)
  125. return TRUE;
  126. pNode = (CChatFriend*)pNode->GetNext();
  127. }
  128. }
  129. return FALSE;
  130. }
  131. CChatFriend* KPlayerChat::GetFriendNode(DWORD dwID)
  132. {
  133. CChatFriend *pNode;
  134. for (int i = 0; i < MAX_FRIEND_TEAM; i++)
  135. {
  136. if (m_cFriendTeam[i].m_nFriendNo <= 0)
  137. continue;
  138. pNode = (CChatFriend*)m_cFriendTeam[i].m_cEveryOne.GetHead();
  139. while (pNode)
  140. {
  141. if (pNode->m_dwID == dwID)
  142. {
  143. return pNode;
  144. }
  145. pNode = (CChatFriend*)pNode->GetNext();
  146. }
  147. }
  148. return NULL;
  149. }
  150. int KPlayerChat::GetTeamNo(DWORD dwID)
  151. {
  152. CChatFriend *pNode;
  153. for (int i = 0; i < MAX_FRIEND_TEAM; i++)
  154. {
  155. if (i != 0 && !m_cFriendTeam[i].m_szTeamName[0])
  156. continue;
  157. if (m_cFriendTeam[i].m_nFriendNo <= 0)
  158. continue;
  159. pNode = (CChatFriend*)m_cFriendTeam[i].m_cEveryOne.GetHead();
  160. while (pNode)
  161. {
  162. if (pNode->m_dwID == dwID)
  163. {
  164. return i;
  165. }
  166. pNode = (CChatFriend*)pNode->GetNext();
  167. }
  168. }
  169. return -1;
  170. }
  171. BOOL KPlayerChat::GetName(DWORD dwID, char *lpszName)
  172. {
  173. if ( !lpszName )
  174. return FALSE;
  175. CChatFriend *pNode;
  176. for (int i = 0; i < MAX_FRIEND_TEAM; i++)
  177. {
  178. if (m_cFriendTeam[i].m_nFriendNo <= 0)
  179. continue;
  180. pNode = (CChatFriend*)m_cFriendTeam[i].m_cEveryOne.GetHead();
  181. while (pNode)
  182. {
  183. if (pNode->m_dwID == dwID)
  184. {
  185. g_StrCpy(lpszName, pNode->m_szName);
  186. return TRUE;
  187. }
  188. pNode = (CChatFriend*)pNode->GetNext();
  189. }
  190. }
  191. return FALSE;
  192. }
  193. #ifndef _SERVER
  194. //---------------------------------------------------------------------------
  195. // 功能:设定当前发送频道
  196. //---------------------------------------------------------------------------
  197. void KPlayerChat::SetCurChannel(int nChannelNo, DWORD dwID, int nIdx)
  198. {
  199. if (nChannelNo <= CHAT_CUR_CHANNEL_NONE || nChannelNo >= CHAT_CUR_CHANNEL_NUM)
  200. return;
  201. switch (nChannelNo)
  202. {
  203. case CHAT_CUR_CHANNEL_SINGLE:
  204. m_nCurChannel = nChannelNo;
  205. this->m_dwTargetID = dwID;
  206. this->m_nTargetIdx = nIdx;
  207. break;
  208. case CHAT_CUR_CHANNEL_SCREENSINGLE:
  209. m_nCurChannel = nChannelNo;
  210. this->m_dwTargetID = dwID;
  211. this->m_nTargetIdx = nIdx;
  212. break;
  213. case CHAT_CUR_CHANNEL_SYSTEM:
  214. // 检测玩家身份,确定是否可以设定为此频道 not end
  215. m_nCurChannel = nChannelNo;
  216. break;
  217. default:
  218. m_nCurChannel = nChannelNo;
  219. break;
  220. }
  221. CoreDataChanged(GDCNI_SEND_CHAT_CHANNEL, 0, 0);
  222. }
  223. #endif
  224. #ifndef _SERVER
  225. //---------------------------------------------------------------------------
  226. // 功能:增加订阅频道
  227. //---------------------------------------------------------------------------
  228. void KPlayerChat::AddChannel(int nChannelNo)
  229. {
  230. if (CHAT_CUR_CHANNEL_NONE >= nChannelNo || nChannelNo >= CHAT_CUR_CHANNEL_NUM)
  231. return;
  232. switch (nChannelNo)
  233. {
  234. case CHAT_CUR_CHANNEL_ALL:
  235. // 玩家身份判断,普通玩家默认订阅此频道,不能取消 not end
  236. m_dwTakeChannel |= g_dwChannelOr[nChannelNo];
  237. break;
  238. default:
  239. m_dwTakeChannel |= g_dwChannelOr[nChannelNo];
  240. break;
  241. }
  242. this->SaveTakeChannelInfo(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name);
  243. SendTakeChannel();
  244. }
  245. #endif
  246. #ifndef _SERVER
  247. //---------------------------------------------------------------------------
  248. // 功能:取消订阅频道
  249. //---------------------------------------------------------------------------
  250. void KPlayerChat::SubChannel(int nChannelNo)
  251. {
  252. if (CHAT_CUR_CHANNEL_NONE >= nChannelNo || nChannelNo >= CHAT_CUR_CHANNEL_NUM)
  253. return;
  254. switch (nChannelNo)
  255. {
  256. case CHAT_CUR_CHANNEL_ALL:
  257. case CHAT_CUR_CHANNEL_SYSTEM:
  258. case CHAT_CUR_CHANNEL_SCREEN:
  259. // 玩家身份判断,普通玩家默认订阅此频道,不能取消 not end
  260. break;
  261. default:
  262. m_dwTakeChannel &= g_dwChannelAnd[nChannelNo];
  263. break;
  264. }
  265. this->SaveTakeChannelInfo(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name);
  266. SendTakeChannel();
  267. }
  268. #endif
  269. #ifndef _SERVER
  270. //---------------------------------------------------------------------------
  271. // 功能:客户端发送订阅频道给服务器
  272. //---------------------------------------------------------------------------
  273. void KPlayerChat::SendTakeChannel()
  274. {
  275. CHAT_SET_CHANNEL_COMMAND sChannel;
  276. sChannel.ProtocolType = c2s_chatsetchannel;
  277. sChannel.m_dwTakeChannel = this->m_dwTakeChannel;
  278. if (g_pClient)
  279. g_pClient->SendPackToServer(&sChannel, sizeof(CHAT_SET_CHANNEL_COMMAND));
  280. }
  281. #endif
  282. #ifndef _SERVER
  283. //---------------------------------------------------------------------------
  284. // 功能:客户端发送聊天语句给服务器
  285. //---------------------------------------------------------------------------
  286. void KPlayerChat::SendSentence(KUiMsgParam *pMsg, char *lpszSentence)
  287. {
  288. if (!lpszSentence || !pMsg || pMsg->nMsgLength <= 0)
  289. return;
  290. int nLength = pMsg->nMsgLength;
  291. if (nLength >= MAX_SENTENCE_LENGTH)
  292. nLength = MAX_SENTENCE_LENGTH - 1;
  293. if (pMsg->eGenre == MSG_G_CHAT)
  294. {
  295. PLAYER_SEND_CHAT_COMMAND sChat;
  296. sChat.ProtocolType = c2s_playersendchat;
  297. sChat.m_wLength = sizeof(PLAYER_SEND_CHAT_COMMAND) - 1 - sizeof(sChat.m_szSentence) + nLength + pMsg->cChatPrefixLen;
  298. sChat.m_btCurChannel = this->m_nCurChannel;
  299. sChat.m_btType = pMsg->eGenre;
  300. sChat.m_btChatPrefixLen = pMsg->cChatPrefixLen;
  301. sChat.m_wSentenceLen = nLength;
  302. sChat.m_dwTargetID = m_dwTargetID;
  303. sChat.m_nTargetIdx = m_nTargetIdx;
  304. memcpy(&sChat.m_szSentence[0], (char*)pMsg->cChatPrefix, pMsg->cChatPrefixLen);
  305. memcpy(&sChat.m_szSentence[pMsg->cChatPrefixLen], lpszSentence, nLength);
  306. if (g_pClient)
  307. g_pClient->SendPackToServer(&sChat, sChat.m_wLength + 1);
  308. if (m_nCurChannel == CHAT_CUR_CHANNEL_SINGLE)
  309. {
  310. char szName[32];
  311. szName[0] = 0;
  312. if (GetName(m_dwTargetID, szName))
  313. {
  314. if (szName[0])
  315. m_cRecorder.SaveSentenceSingle(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name, szName, Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name, lpszSentence);
  316. }
  317. }
  318. else
  319. {
  320. this->m_cRecorder.SaveSentenceChannel(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name, Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name, lpszSentence);
  321. }
  322. }
  323. else if (pMsg->eGenre == MSG_G_CMD) // not end
  324. {
  325. }
  326. }
  327. #endif
  328. #ifndef _SERVER
  329. //---------------------------------------------------------------------------
  330. // 功能:客户端发送聊天语句给服务器(QQ专用)
  331. //---------------------------------------------------------------------------
  332. void KPlayerChat::QQSendSentence(DWORD dwID, int nIdx, KUiMsgParam *pMsg, char *lpszSentence)
  333. {
  334. if (!lpszSentence || !pMsg || pMsg->nMsgLength <= 0)
  335. return;
  336. int nLength = pMsg->nMsgLength;
  337. if (nLength >= MAX_SENTENCE_LENGTH)
  338. nLength = MAX_SENTENCE_LENGTH - 1;
  339. PLAYER_SEND_CHAT_COMMAND sChat;
  340. sChat.ProtocolType = c2s_playersendchat;
  341. sChat.m_wLength = sizeof(PLAYER_SEND_CHAT_COMMAND) - 1 - sizeof(sChat.m_szSentence) + nLength + pMsg->cChatPrefixLen;
  342. sChat.m_btCurChannel = CHAT_CUR_CHANNEL_SINGLE;
  343. sChat.m_btType = pMsg->eGenre;
  344. sChat.m_btChatPrefixLen = pMsg->cChatPrefixLen;
  345. sChat.m_wSentenceLen = nLength;
  346. sChat.m_dwTargetID = dwID;
  347. sChat.m_nTargetIdx = nIdx;
  348. memcpy(&sChat.m_szSentence[0], (char*)pMsg->cChatPrefix, pMsg->cChatPrefixLen);
  349. memcpy(&sChat.m_szSentence[pMsg->cChatPrefixLen], lpszSentence, nLength);
  350. if (g_pClient)
  351. g_pClient->SendPackToServer(&sChat, sChat.m_wLength + 1);
  352. char szName[32];
  353. szName[0] = 0;
  354. if (GetName(dwID, szName))
  355. {
  356. if (szName[0])
  357. m_cRecorder.SaveSentenceSingle(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name, szName, Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name, lpszSentence);
  358. }
  359. }
  360. #endif
  361. //---------------------------------------------------------------------------
  362. // 功能:服务器收到客户端发来的订阅聊天频道信息
  363. //---------------------------------------------------------------------------
  364. void KPlayerChat::SetTakeChannel(DWORD dwChannel)
  365. {
  366. // 玩家身份判断,不同玩家系统赋予的权限不同 not end
  367. m_dwTakeChannel = dwChannel | g_dwChannelOr[CHAT_CUR_CHANNEL_ALL] | g_dwChannelOr[CHAT_CUR_CHANNEL_SCREEN] | g_dwChannelOr[CHAT_CUR_CHANNEL_SYSTEM];
  368. }
  369. #ifdef _SERVER
  370. //---------------------------------------------------------------------------
  371. // 功能:服务器收到客户端发来的聊天信息
  372. //---------------------------------------------------------------------------
  373. void KPlayerChat::ServerSendChat(int nPlayerIdx, BYTE* pProtocol)
  374. {
  375. if (!pProtocol)
  376. return;
  377. PLAYER_SEND_CHAT_COMMAND *pChat = (PLAYER_SEND_CHAT_COMMAND*)pProtocol;
  378. int nLen = pChat->m_wSentenceLen;
  379. if (pChat->m_btCurChannel <= CHAT_CUR_CHANNEL_NONE || pChat->m_btCurChannel >= CHAT_CUR_CHANNEL_NUM)
  380. return;
  381. if (pChat->m_btChatPrefixLen > CHAT_MSG_PREFIX_MAX_LEN || pChat->m_wSentenceLen >= MAX_SENTENCE_LENGTH)
  382. return;
  383. if (pChat->m_wLength != sizeof(PLAYER_SEND_CHAT_COMMAND) - 1 - sizeof(pChat->m_szSentence) + pChat->m_btChatPrefixLen + pChat->m_wSentenceLen)
  384. {
  385. g_DebugLog("[chat]聊天数据包错误!");
  386. return;
  387. }
  388. if (pChat->m_btType == MSG_G_CHAT)
  389. {
  390. switch (pChat->m_btCurChannel)
  391. {
  392. case CHAT_CUR_CHANNEL_ALL:
  393. {
  394. // 检查玩家权限,普通玩家没有这个权限 not end
  395. break;
  396. if (m_nTimer < CHAT_SPEED)
  397. break;
  398. m_nTimer = 0;
  399. PLAYER_SEND_CHAT_SYNC sChat;
  400. sChat.ProtocolType = s2c_playersendchat;
  401. sChat.m_btCurChannel = pChat->m_btCurChannel;
  402. sChat.m_btNameLen = strlen(Npc[Player[nPlayerIdx].m_nIndex].Name);
  403. sChat.m_btChatPrefixLen = pChat->m_btChatPrefixLen;
  404. sChat.m_wSentenceLen = pChat->m_wSentenceLen;
  405. sChat.m_dwSourceID = Player[nPlayerIdx].m_dwID; // 发送者的player id 可能需要根据玩家身份改动
  406. sChat.m_wLength = sizeof(PLAYER_SEND_CHAT_SYNC) - 1 - sizeof(sChat.m_szSentence) + sChat.m_btNameLen + sChat.m_btChatPrefixLen + sChat.m_wSentenceLen;
  407. memcpy(&sChat.m_szSentence[0], Npc[Player[nPlayerIdx].m_nIndex].Name, sChat.m_btNameLen); // 可能需要根据玩家身份改动
  408. memcpy(&sChat.m_szSentence[sChat.m_btNameLen], &pChat->m_szSentence[0], sChat.m_btChatPrefixLen);
  409. memcpy(&sChat.m_szSentence[sChat.m_btNameLen + sChat.m_btChatPrefixLen], &pChat->m_szSentence[pChat->m_btChatPrefixLen], sChat.m_wSentenceLen); // 可能需要根据玩家身份改动
  410. int nTargetIdx;
  411. nTargetIdx = PlayerSet.GetFirstPlayer();
  412. while (nTargetIdx)
  413. {
  414. g_pServer->PackDataToClient(Player[nTargetIdx].m_nNetConnectIdx, (BYTE*)&sChat, sChat.m_wLength + 1);
  415. nTargetIdx = PlayerSet.GetNextPlayer();
  416. }
  417. }
  418. break;
  419. case CHAT_CUR_CHANNEL_SCREEN:
  420. {
  421. if (m_nTimer < CHAT_SPEED)
  422. break;
  423. m_nTimer = 0;
  424. PLAYER_SEND_CHAT_SYNC sChat;
  425. sChat.ProtocolType = s2c_playersendchat;
  426. sChat.m_btCurChannel = pChat->m_btCurChannel;
  427. sChat.m_btNameLen = strlen(Npc[Player[nPlayerIdx].m_nIndex].Name);
  428. sChat.m_btChatPrefixLen = pChat->m_btChatPrefixLen;
  429. sChat.m_wSentenceLen = pChat->m_wSentenceLen;
  430. sChat.m_dwSourceID = Npc[Player[nPlayerIdx].m_nIndex].m_dwID; // 此处传的是发送者的 npc id
  431. sChat.m_wLength = sizeof(PLAYER_SEND_CHAT_SYNC) - 1 - sizeof(sChat.m_szSentence) + sChat.m_btNameLen + sChat.m_btChatPrefixLen + sChat.m_wSentenceLen;
  432. memcpy(&sChat.m_szSentence[0], Npc[Player[nPlayerIdx].m_nIndex].Name, sChat.m_btNameLen); // 可能需要根据玩家身份改动
  433. memcpy(&sChat.m_szSentence[sChat.m_btNameLen], &pChat->m_szSentence[0], sChat.m_btChatPrefixLen);
  434. memcpy(&sChat.m_szSentence[sChat.m_btNameLen + sChat.m_btChatPrefixLen], &pChat->m_szSentence[pChat->m_btChatPrefixLen], sChat.m_wSentenceLen); // 可能需要根据玩家身份改动
  435. #ifdef _CHAT_SCRIPT_OPEN
  436. if (TextGMFilter(nPlayerIdx,(const char *) (pChat->m_szSentence + pChat->m_btChatPrefixLen), sChat.m_wSentenceLen))
  437. return;
  438. #endif
  439. Npc[Player[nPlayerIdx].m_nIndex].SendDataToNearRegion((BYTE*)&sChat, sChat.m_wLength + 1);
  440. }
  441. break;
  442. case CHAT_CUR_CHANNEL_SINGLE:
  443. {
  444. DWORD dwCheckID = 0;
  445. int nIndex = 0;
  446. if (pChat->m_nTargetIdx <= 0 || pChat->m_nTargetIdx >= MAX_PLAYER)
  447. {
  448. int nSubWorld = Npc[Player[nPlayerIdx].m_nIndex].m_SubWorldIndex;
  449. int nRegion = Npc[Player[nPlayerIdx].m_nIndex].m_RegionIndex;
  450. nIndex = SubWorld[nSubWorld].m_Region[nRegion].FindPlayer(pChat->m_dwTargetID);
  451. if (nIndex <= 0)
  452. {
  453. for (int i = 0; i < 8; i++)
  454. {
  455. int nConRegion = SubWorld[nSubWorld].m_Region[nRegion].m_nConnectRegion[i];
  456. if (nConRegion == -1)
  457. continue;
  458. nIndex = SubWorld[nSubWorld].m_Region[nConRegion].FindPlayer(pChat->m_dwTargetID);
  459. if (nIndex > 0)
  460. break;
  461. }
  462. if (nIndex <= 0)
  463. return;
  464. }
  465. dwCheckID = Player[nIndex].m_dwID;
  466. // return;
  467. }
  468. else
  469. {
  470. dwCheckID = pChat->m_dwTargetID;
  471. nIndex = pChat->m_nTargetIdx;
  472. }
  473. if (Player[nIndex].m_nIndex == 0 || 
  474. Player[nIndex].m_dwID != dwCheckID)
  475. return;
  476. PLAYER_SEND_CHAT_SYNC sChat;
  477. sChat.ProtocolType = s2c_playersendchat;
  478. sChat.m_btCurChannel = pChat->m_btCurChannel;
  479. sChat.m_btNameLen = 0;
  480. sChat.m_btChatPrefixLen = pChat->m_btChatPrefixLen;
  481. sChat.m_wSentenceLen = pChat->m_wSentenceLen;
  482. sChat.m_dwSourceID = Player[nPlayerIdx].m_dwID;
  483. sChat.m_wLength = sizeof(PLAYER_SEND_CHAT_SYNC) - 1 - sizeof(sChat.m_szSentence) + sChat.m_btNameLen + sChat.m_btChatPrefixLen + sChat.m_wSentenceLen;
  484. // QQ聊天不传名字
  485. // memcpy(&sChat.m_szSentence[0], Npc[Player[nPlayerIdx].m_nIndex].Name, sChat.m_btNameLen);
  486. memcpy(&sChat.m_szSentence[sChat.m_btNameLen], &pChat->m_szSentence[0], sChat.m_btChatPrefixLen);
  487. memcpy(&sChat.m_szSentence[sChat.m_btNameLen + sChat.m_btChatPrefixLen], &pChat->m_szSentence[pChat->m_btChatPrefixLen], sChat.m_wSentenceLen); // 可能需要根据玩家身份改动
  488. g_pServer->PackDataToClient(Player[nIndex].m_nNetConnectIdx, (BYTE*)&sChat, sChat.m_wLength + 1);
  489. }
  490. break;
  491. case CHAT_CUR_CHANNEL_TEAM:
  492. {
  493. if (m_nTimer < CHAT_SPEED)
  494. break;
  495. m_nTimer = 0;
  496. if ( !Player[nPlayerIdx].m_cTeam.m_nFlag ) // 不在队伍中
  497. return;
  498. PLAYER_SEND_CHAT_SYNC sChat;
  499. sChat.ProtocolType = s2c_playersendchat;
  500. sChat.m_btCurChannel = pChat->m_btCurChannel;
  501. sChat.m_btNameLen = strlen(Npc[Player[nPlayerIdx].m_nIndex].Name);
  502. sChat.m_btChatPrefixLen = pChat->m_btChatPrefixLen;
  503. sChat.m_wSentenceLen = pChat->m_wSentenceLen;
  504. sChat.m_dwSourceID = Npc[Player[nPlayerIdx].m_nIndex].m_dwID; // 此处传的是发送者的 npc id
  505. sChat.m_wLength = sizeof(PLAYER_SEND_CHAT_SYNC) - 1 - sizeof(sChat.m_szSentence) + sChat.m_btNameLen + sChat.m_btChatPrefixLen + sChat.m_wSentenceLen;
  506. memcpy(&sChat.m_szSentence[0], Npc[Player[nPlayerIdx].m_nIndex].Name, sChat.m_btNameLen); // 可能需要根据玩家身份改动
  507. memcpy(&sChat.m_szSentence[sChat.m_btNameLen], &pChat->m_szSentence[0], sChat.m_btChatPrefixLen);
  508. memcpy(&sChat.m_szSentence[sChat.m_btNameLen + sChat.m_btChatPrefixLen], &pChat->m_szSentence[pChat->m_btChatPrefixLen], sChat.m_wSentenceLen); // 可能需要根据玩家身份改动
  509. int nTargetIdx;
  510. // 给队长发
  511. nTargetIdx = g_Team[Player[nPlayerIdx].m_cTeam.m_nID].m_nCaptain;
  512. if (nTargetIdx != nPlayerIdx && (Player[nTargetIdx].m_cChat.m_dwTakeChannel & g_dwChannelOr[CHAT_CUR_CHANNEL_TEAM]))
  513. g_pServer->PackDataToClient(Player[nTargetIdx].m_nNetConnectIdx, (BYTE*)&sChat, sChat.m_wLength + 1);
  514. // 给队员发
  515. for (int i = 0; i < MAX_TEAM_MEMBER; i++)
  516. {
  517. nTargetIdx = g_Team[Player[nPlayerIdx].m_cTeam.m_nID].m_nMember[i];
  518. if (nTargetIdx < 0 || nTargetIdx == nPlayerIdx)
  519. continue;
  520. if (Player[nTargetIdx].m_cChat.m_dwTakeChannel & g_dwChannelOr[CHAT_CUR_CHANNEL_TEAM])
  521. g_pServer->PackDataToClient(Player[nTargetIdx].m_nNetConnectIdx, (BYTE*)&sChat, sChat.m_wLength + 1);
  522. }
  523. }
  524. break;
  525. case CHAT_CUR_CHANNEL_FACTION:
  526. {
  527. if (m_nTimer < CHAT_SPEED)
  528. break;
  529. m_nTimer = 0;
  530. int nFaction = Player[nPlayerIdx].m_cFaction.m_nCurFaction;
  531. if ( nFaction < 0) // 不在门派中
  532. return;
  533. PLAYER_SEND_CHAT_SYNC sChat;
  534. sChat.ProtocolType = s2c_playersendchat;
  535. sChat.m_btCurChannel = pChat->m_btCurChannel;
  536. sChat.m_btNameLen = strlen(Npc[Player[nPlayerIdx].m_nIndex].Name);
  537. sChat.m_btChatPrefixLen = pChat->m_btChatPrefixLen;
  538. sChat.m_wSentenceLen = pChat->m_wSentenceLen;
  539. sChat.m_dwSourceID = Npc[Player[nPlayerIdx].m_nIndex].m_dwID; // 此处传的是发送者的 npc id
  540. sChat.m_wLength = sizeof(PLAYER_SEND_CHAT_SYNC) - 1 - sizeof(sChat.m_szSentence) + sChat.m_btNameLen + sChat.m_btChatPrefixLen + sChat.m_wSentenceLen;
  541. memcpy(&sChat.m_szSentence[0], Npc[Player[nPlayerIdx].m_nIndex].Name, sChat.m_btNameLen); // 可能需要根据玩家身份改动
  542. memcpy(&sChat.m_szSentence[sChat.m_btNameLen], &pChat->m_szSentence[0], sChat.m_btChatPrefixLen);
  543. memcpy(&sChat.m_szSentence[sChat.m_btNameLen + sChat.m_btChatPrefixLen], &pChat->m_szSentence[pChat->m_btChatPrefixLen], sChat.m_wSentenceLen); // 可能需要根据玩家身份改动
  544. int nTargetIdx;
  545. nTargetIdx = PlayerSet.GetFirstPlayer();
  546. while (nTargetIdx)
  547. {
  548. if (Player[nTargetIdx].m_cFaction.m_nCurFaction == nFaction && (Player[nTargetIdx].m_cChat.m_dwTakeChannel & g_dwChannelOr[CHAT_CUR_CHANNEL_FACTION]))
  549. g_pServer->PackDataToClient(Player[nTargetIdx].m_nNetConnectIdx, (BYTE*)&sChat, sChat.m_wLength + 1);
  550. nTargetIdx = PlayerSet.GetNextPlayer();
  551. }
  552. }
  553. break;
  554. case CHAT_CUR_CHANNEL_TONG:
  555. {
  556. if (m_nTimer < CHAT_SPEED)
  557. break;
  558. m_nTimer = 0;
  559. }
  560. break;
  561. case CHAT_CUR_CHANNEL_SCREENSINGLE:
  562. {
  563. if (m_nTimer < CHAT_SPEED)
  564. break;
  565. m_nTimer = 0;
  566. int nTargetIdx;
  567. nTargetIdx = Player[nPlayerIdx].FindAroundPlayer(pChat->m_dwTargetID);
  568. if (nTargetIdx == -1)
  569. return;
  570. if ( !Player[nTargetIdx].m_cChat.CheckTalkChannel(CHAT_CUR_CHANNEL_SCREENSINGLE) )
  571. {
  572. CHAT_SCREENSINGLE_ERROR_SYNC sError;
  573. sError.ProtocolType = s2c_chatscreensingleerror;
  574. sError.m_btError = 0;
  575. memset(sError.m_szName, 0, sizeof(sError.m_szName));
  576. g_StrCpy(sError.m_szName, Npc[Player[nTargetIdx].m_nIndex].Name);
  577. sError.m_wLength = 2 + 1 + strlen(sError.m_szName);
  578. g_pServer->PackDataToClient(Player[nPlayerIdx].m_nNetConnectIdx, (BYTE*)&sError, sError.m_wLength + 1);
  579. return;
  580. }
  581. PLAYER_SEND_CHAT_SYNC sChat;
  582. sChat.ProtocolType = s2c_playersendchat;
  583. sChat.m_btCurChannel = pChat->m_btCurChannel;
  584. sChat.m_btNameLen = strlen(Npc[Player[nPlayerIdx].m_nIndex].Name);
  585. sChat.m_btChatPrefixLen = pChat->m_btChatPrefixLen;
  586. sChat.m_wSentenceLen = pChat->m_wSentenceLen;
  587. sChat.m_dwSourceID = Npc[Player[nPlayerIdx].m_nIndex].m_dwID; // 此处传的是发送者的 npc id
  588. sChat.m_wLength = sizeof(PLAYER_SEND_CHAT_SYNC) - 1 - sizeof(sChat.m_szSentence) + sChat.m_btNameLen + sChat.m_btChatPrefixLen + sChat.m_wSentenceLen;
  589. memcpy(&sChat.m_szSentence[0], Npc[Player[nPlayerIdx].m_nIndex].Name, sChat.m_btNameLen); // 可能需要根据玩家身份改动
  590. memcpy(&sChat.m_szSentence[sChat.m_btNameLen], &pChat->m_szSentence[0], sChat.m_btChatPrefixLen);
  591. memcpy(&sChat.m_szSentence[sChat.m_btNameLen + sChat.m_btChatPrefixLen], &pChat->m_szSentence[pChat->m_btChatPrefixLen], sChat.m_wSentenceLen); // 可能需要根据玩家身份改动
  592. g_pServer->PackDataToClient(Player[nTargetIdx].m_nNetConnectIdx, (BYTE*)&sChat, sChat.m_wLength + 1);
  593. }
  594. break;
  595. case CHAT_CUR_CHANNEL_SYSTEM:
  596. // 在此种情况下普通玩家不允许使用此频道 not end
  597. if (pChat->m_dwTargetID == 0) // to all
  598. {
  599. char szSentence[MAX_SENTENCE_LENGTH], szPrefix[CHAT_MSG_PREFIX_MAX_LEN];
  600. memcpy(szSentence, &pChat->m_szSentence[pChat->m_btChatPrefixLen], nLen); // 可能需要根据玩家身份改动
  601. szSentence[nLen] = 0;
  602. memcpy(szPrefix, &pChat->m_szSentence[0], pChat->m_btChatPrefixLen);
  603. KPlayerChat::SendSystemInfo(0, 0, MESSAGE_SYSTEM_ANNOUCE_HEAD, szSentence, nLen);
  604. }
  605. else
  606. {
  607. char szSentence[MAX_SENTENCE_LENGTH], szPrefix[CHAT_MSG_PREFIX_MAX_LEN];
  608. int nIdx;
  609. memcpy(szSentence, &pChat->m_szSentence[pChat->m_btChatPrefixLen], nLen); // 可能需要根据玩家身份改动
  610. szSentence[nLen] = 0;
  611. memcpy(szPrefix, &pChat->m_szSentence[0], pChat->m_btChatPrefixLen);
  612. nIdx = PlayerSet.FindSame(pChat->m_dwTargetID);
  613. if (nIdx > 0)
  614. KPlayerChat::SendSystemInfo(1, nIdx, MESSAGE_SYSTEM_ANNOUCE_HEAD, szSentence, nLen);
  615. }
  616. break;
  617. }
  618. }
  619. else if (pChat->m_btType == MSG_G_CMD)
  620. {
  621. }
  622. else
  623. {
  624. return;
  625. }
  626. }
  627. #endif
  628. #ifndef _SERVER
  629. //---------------------------------------------------------------------------
  630. // 功能:客户端收到聊天语句
  631. //---------------------------------------------------------------------------
  632. void KPlayerChat::GetChat(PLAYER_SEND_CHAT_SYNC *pChat)
  633. {
  634. if (!pChat)
  635. return;
  636. char szBuf[MAX_SENTENCE_LENGTH];
  637. KUiMsgParam Param;
  638. Param.cChatPrefixLen = pChat->m_btChatPrefixLen;
  639. Param.nMsgLength = pChat->m_wSentenceLen;
  640. memcpy(szBuf, &pChat->m_szSentence[pChat->m_btNameLen + pChat->m_btChatPrefixLen], pChat->m_wSentenceLen);
  641. szBuf[pChat->m_wSentenceLen] = 0;
  642. memset(Param.cChatPrefix, 0, sizeof(Param.cChatPrefix));
  643. memset(Param.szName, 0, sizeof(Param.szName));
  644. switch (pChat->m_btCurChannel)
  645. {
  646. case CHAT_CUR_CHANNEL_ALL:
  647. {
  648. if (pChat->m_dwSourceID == Player[CLIENT_PLAYER_INDEX].m_dwID)
  649. return;
  650. memcpy(Param.cChatPrefix, &pChat->m_szSentence[pChat->m_btNameLen], pChat->m_btChatPrefixLen);
  651. memcpy(Param.szName, &pChat->m_szSentence[0], pChat->m_btNameLen);
  652. Param.szName[pChat->m_btNameLen] = 0;
  653. CoreDataChanged(GDCNI_MSG_ARRIVAL, (unsigned int)szBuf, (int)&Param);
  654. }
  655. break;
  656. case CHAT_CUR_CHANNEL_SCREEN:
  657. {
  658. if (pChat->m_dwSourceID == Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_dwID)
  659. return;
  660. int nTalker = NpcSet.SearchID(pChat->m_dwSourceID);
  661. if (nTalker == 0)
  662. return;
  663. memcpy(Param.cChatPrefix, &pChat->m_szSentence[pChat->m_btNameLen], pChat->m_btChatPrefixLen);
  664. memcpy(Param.szName, &pChat->m_szSentence[0], pChat->m_btNameLen);
  665. Param.szName[pChat->m_btNameLen] = 0;
  666. CoreDataChanged(GDCNI_MSG_ARRIVAL, (unsigned int)szBuf, (int)&Param);
  667. }
  668. break;
  669. case CHAT_CUR_CHANNEL_SINGLE:
  670. {
  671. if (pChat->m_dwSourceID == Player[CLIENT_PLAYER_INDEX].m_dwID)
  672. return;
  673. CChatFriend *pFriend = NULL;
  674. pFriend = this->GetFriendNode(pChat->m_dwSourceID);
  675. if ( pFriend == NULL )
  676. {
  677. // TODO: Temp change by wanli
  678. /* CHAT_REDELETE_FRIEND_COMMAND sApply;
  679. sApply.ProtocolType = c2s_chatredeletefriend;
  680. sApply.m_dwID = pChat->m_dwSourceID;
  681. if (g_pClient)
  682. g_pClient->SendPackToServer(&sApply, sizeof(CHAT_REDELETE_FRIEND_COMMAND));
  683. break;*/
  684. int nIndex = NpcSet.SearchNameID(pChat->m_dwSourceID);
  685. if (nIndex == 0)
  686. break;
  687. KUiChatMessage sMsg;
  688. sMsg.nContentLen = pChat->m_wSentenceLen;
  689. memcpy(sMsg.szContent, &pChat->m_szSentence[pChat->m_btNameLen + pChat->m_btChatPrefixLen], sMsg.nContentLen);
  690. sMsg.szContent[sMsg.nContentLen] = 0;
  691. if (pChat->m_btChatPrefixLen == 4)
  692. {
  693. ((char*)(&sMsg.uColor))[3] = pChat->m_szSentence[pChat->m_btNameLen];
  694. ((char*)(&sMsg.uColor))[2] = pChat->m_szSentence[pChat->m_btNameLen + 1];
  695. ((char*)(&sMsg.uColor))[1] = pChat->m_szSentence[pChat->m_btNameLen + 2];
  696. ((char*)(&sMsg.uColor))[0] = pChat->m_szSentence[pChat->m_btNameLen + 3];
  697. }
  698. else
  699. {
  700. sMsg.uColor = 0;
  701. }
  702. KUiPlayerItem sPlayer;
  703. strcpy(sPlayer.Name, Npc[nIndex].Name);
  704. sPlayer.uId = pChat->m_dwSourceID;
  705. sPlayer.nIndex = 0;
  706. sPlayer.nData = 0;
  707. CoreDataChanged(GDCNI_CHAT_MESSAGE, (unsigned int)&sMsg, (int)&sPlayer);
  708. break;
  709. }
  710. KUiChatMessage sMsg;
  711. sMsg.nContentLen = pChat->m_wSentenceLen;
  712. memcpy(sMsg.szContent, &pChat->m_szSentence[pChat->m_btNameLen + pChat->m_btChatPrefixLen], sMsg.nContentLen);
  713. sMsg.szContent[sMsg.nContentLen] = 0;
  714. if (pChat->m_btChatPrefixLen == 4)
  715. {
  716. ((char*)(&sMsg.uColor))[3] = pChat->m_szSentence[pChat->m_btNameLen];
  717. ((char*)(&sMsg.uColor))[2] = pChat->m_szSentence[pChat->m_btNameLen + 1];
  718. ((char*)(&sMsg.uColor))[1] = pChat->m_szSentence[pChat->m_btNameLen + 2];
  719. ((char*)(&sMsg.uColor))[0] = pChat->m_szSentence[pChat->m_btNameLen + 3];
  720. }
  721. else
  722. {
  723. sMsg.uColor = 0;
  724. }
  725. KUiPlayerItem sPlayer;
  726. strcpy(sPlayer.Name, pFriend->m_szName);
  727. sPlayer.uId = pFriend->m_dwID;
  728. sPlayer.nIndex = pFriend->m_nPlayerIdx;
  729. sPlayer.nData = 0;
  730. CoreDataChanged(GDCNI_CHAT_MESSAGE, (unsigned int)&sMsg, (int)&sPlayer);
  731. }
  732. break;
  733. case CHAT_CUR_CHANNEL_TEAM:
  734. {
  735. if (pChat->m_dwSourceID == Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_dwID)
  736. return;
  737. memcpy(Param.cChatPrefix, &pChat->m_szSentence[pChat->m_btNameLen], pChat->m_btChatPrefixLen);
  738. memcpy(Param.szName, &pChat->m_szSentence[0], pChat->m_btNameLen);
  739. Param.szName[pChat->m_btNameLen] = 0;
  740. CoreDataChanged(GDCNI_MSG_ARRIVAL, (unsigned int)szBuf, (int)&Param);
  741. }
  742. break;
  743. case CHAT_CUR_CHANNEL_FACTION:
  744. {
  745. if (pChat->m_dwSourceID == Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].m_dwID)
  746. return;
  747. memcpy(Param.cChatPrefix, &pChat->m_szSentence[pChat->m_btNameLen], pChat->m_btChatPrefixLen);
  748. memcpy(Param.szName, &pChat->m_szSentence[0], pChat->m_btNameLen);
  749. Param.szName[pChat->m_btNameLen] = 0;
  750. CoreDataChanged(GDCNI_MSG_ARRIVAL, (unsigned int)szBuf, (int)&Param);
  751. }
  752. break;
  753. case CHAT_CUR_CHANNEL_TONG:
  754. {
  755. if (pChat->m_dwSourceID == Player[CLIENT_PLAYER_INDEX].m_dwID)
  756. return;
  757. memcpy(Param.cChatPrefix, &pChat->m_szSentence[pChat->m_btNameLen], pChat->m_btChatPrefixLen);
  758. memcpy(Param.szName, &pChat->m_szSentence[0], pChat->m_btNameLen);
  759. Param.szName[pChat->m_btNameLen] = 0;
  760. CoreDataChanged(GDCNI_MSG_ARRIVAL, (unsigned int)szBuf, (int)&Param);
  761. }
  762. break;
  763. case CHAT_CUR_CHANNEL_SCREENSINGLE:
  764. {
  765. memcpy(Param.cChatPrefix, &pChat->m_szSentence[pChat->m_btNameLen], pChat->m_btChatPrefixLen);
  766. memcpy(Param.szName, &pChat->m_szSentence[0], pChat->m_btNameLen);
  767. Param.szName[pChat->m_btNameLen] = 0;
  768. CoreDataChanged(GDCNI_MSG_ARRIVAL, (unsigned int)szBuf, (int)&Param);
  769. }
  770. break;
  771. case CHAT_CUR_CHANNEL_SYSTEM:
  772. {
  773. memcpy(Param.cChatPrefix, &pChat->m_szSentence[pChat->m_btNameLen], pChat->m_btChatPrefixLen);
  774. memcpy(Param.szName, &pChat->m_szSentence[0], pChat->m_btNameLen);
  775. Param.szName[pChat->m_btNameLen] = 0;
  776. CoreDataChanged(GDCNI_MSG_ARRIVAL, (unsigned int)szBuf, (int)&Param);
  777. }
  778. break;
  779. }
  780. // 保存聊天纪录
  781. if (pChat->m_btCurChannel == CHAT_CUR_CHANNEL_SINGLE)
  782. {
  783. char szName[32], szSentence[MAX_SENTENCE_LENGTH];
  784. memcpy(szName, &pChat->m_szSentence[0], pChat->m_btNameLen);
  785. szName[pChat->m_btNameLen] = 0;
  786. memcpy(szSentence, &pChat->m_szSentence[pChat->m_btNameLen + pChat->m_btChatPrefixLen], pChat->m_wSentenceLen);
  787. szSentence[pChat->m_wSentenceLen] = 0;
  788. m_cRecorder.SaveSentenceSingle(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name, szName, szName, szSentence);
  789. }
  790. else
  791. {
  792. char szName[32], szSentence[MAX_SENTENCE_LENGTH];
  793. memcpy(szName, &pChat->m_szSentence[0], pChat->m_btNameLen);
  794. szName[pChat->m_btNameLen] = 0;
  795. memcpy(szSentence, &pChat->m_szSentence[pChat->m_btNameLen + pChat->m_btChatPrefixLen], pChat->m_wSentenceLen);
  796. szSentence[pChat->m_wSentenceLen] = 0;
  797. m_cRecorder.SaveSentenceChannel(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name, szName, szSentence);
  798. }
  799. }
  800. #endif
  801. #ifndef _SERVER
  802. //---------------------------------------------------------------------------
  803. // 功能:申请添加聊天好友
  804. //---------------------------------------------------------------------------
  805. void KPlayerChat::ApplyAddFriend(DWORD dwNpcID, char *lpszSentence/* = NULL*/)
  806. {
  807. if (dwNpcID <= 0)
  808. return;
  809. char szName[32];
  810. szName[0] = 0;
  811. if (this->GetName(dwNpcID, szName))
  812. {
  813. // 通知界面此人已经是他的好友了
  814. KSystemMessage sMsg;
  815. sprintf(sMsg.szMessage, MSG_CHAT_FRIEND_HAD_IN, szName);
  816. sMsg.eType = SMT_FRIEND;
  817. sMsg.byConfirmType = SMCT_CLICK;
  818. sMsg.byPriority = 1;
  819. sMsg.byParamSize = 0;
  820. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  821. return;
  822. }
  823. CHAT_APPLY_ADD_FRIEND_COMMAND sAdd;
  824. sAdd.ProtocolType = c2s_chatapplyaddfriend;
  825. sAdd.m_dwTargetNpcID = dwNpcID;
  826. memset(sAdd.m_szInfo, 0, sizeof(sAdd.m_szInfo));
  827. if (lpszSentence)
  828. {
  829. if (strlen(lpszSentence) < sizeof(sAdd.m_szInfo))
  830. strcpy(sAdd.m_szInfo, lpszSentence);
  831. else
  832. memcpy(sAdd.m_szInfo, lpszSentence, sizeof(sAdd.m_szInfo) - 1);
  833. }
  834. sAdd.m_wLength = sizeof(CHAT_APPLY_ADD_FRIEND_COMMAND) - 1 - sizeof(sAdd.m_szInfo) + strlen(sAdd.m_szInfo);
  835. if (g_pClient)
  836. g_pClient->SendPackToServer(&sAdd, sAdd.m_wLength + 1);
  837. }
  838. #endif
  839. #ifndef _SERVER
  840. //---------------------------------------------------------------------------
  841. // 功能:界面获取聊天好友添加申请人信息
  842. //---------------------------------------------------------------------------
  843. BOOL KPlayerChat::GetApplyOneInfo(int *lpnPlayerIdx, char *lpszName, char *lpszInfo)
  844. {
  845. if ( m_cApplyAddList.IsEmpty() )
  846. return FALSE;
  847. if (!lpnPlayerIdx || !lpszName || !lpszInfo)
  848. return FALSE;
  849. CChatApplyListNode *pApply = NULL;
  850. BOOL bFind = FALSE;
  851. pApply = (CChatApplyListNode*)m_cApplyAddList.GetHead();
  852. while (pApply)
  853. {
  854. if ( !pApply->m_nAccessFlag )
  855. {
  856. bFind = TRUE;
  857. break;
  858. }
  859. pApply = (CChatApplyListNode*)pApply->GetNext();
  860. }
  861. if ( !bFind )
  862. return FALSE;
  863. pApply->m_nAccessFlag = 1;
  864. *lpnPlayerIdx = pApply->m_nPlayerIdx;
  865. strcpy(lpszName, pApply->m_szName);
  866. strcpy(lpszInfo, pApply->m_szInfo);
  867. return TRUE;
  868. }
  869. #endif
  870. #ifndef _SERVER
  871. //---------------------------------------------------------------------------
  872. // 功能:保存所有好友分组信息
  873. // char *lpszName : 人名
  874. //---------------------------------------------------------------------------
  875. void KPlayerChat::SaveTeamInfo(char *lpszName)
  876. {
  877. if (!lpszName || !lpszName[0])
  878. return;
  879. // 产生出相应路径
  880. char szPath[MAX_PATH], szBuf[MAX_PATH];
  881. g_StrCpy(szPath, CHAT_PATH);
  882. g_StrCat(szPath, "\");
  883. g_StrCat(szPath, lpszName);
  884. g_CreatePath(szPath);
  885. // g_SetFilePath(szPath);
  886. KIniFile cTeam;
  887. char szKey[32], szSect[64];
  888. int i;
  889. // 保存组名
  890. for (i = 0; i < MAX_FRIEND_TEAM; i++)
  891. {
  892. sprintf(szKey, "%d", i);
  893. cTeam.WriteString("TeamName", szKey, m_cFriendTeam[i].m_szTeamName);
  894. }
  895. // 保存每个组成员信息
  896. for (i = 0; i < MAX_FRIEND_TEAM; i++)
  897. {
  898. if ( !m_cFriendTeam[i].m_szTeamName[0] )
  899. continue;
  900. sprintf(szSect, "T_%s", m_cFriendTeam[i].m_szTeamName);
  901. cTeam.WriteInteger(szSect, "FriendNo", m_cFriendTeam[i].m_nFriendNo);
  902. int j = 0;
  903. CChatFriend *pOne;
  904. pOne = (CChatFriend*)m_cFriendTeam[i].m_cEveryOne.GetHead();
  905. while (pOne)
  906. {
  907. sprintf(szKey, "%d", j);
  908. cTeam.WriteString(szSect, szKey, pOne->m_szName);
  909. pOne = (CChatFriend*)pOne->GetNext();
  910. j++;
  911. }
  912. }
  913. g_UnitePathAndName(szPath, CHAT_TEAM_INFO_FILE_NAME, szBuf);
  914. cTeam.Save(szBuf);
  915. }
  916. #endif
  917. #ifndef _SERVER
  918. //---------------------------------------------------------------------------
  919. // 功能:保存频道订阅信息
  920. // char *lpszName : 人名
  921. //---------------------------------------------------------------------------
  922. void KPlayerChat::SaveTakeChannelInfo(char *lpszName)
  923. {
  924. if (!lpszName || !lpszName[0])
  925. return;
  926. // 产生出相应路径
  927. char szPath[MAX_PATH], szBuf[MAX_PATH];
  928. g_StrCpy(szPath, CHAT_PATH);
  929. g_StrCat(szPath, "\");
  930. g_StrCat(szPath, lpszName);
  931. g_CreatePath(szPath);
  932. // g_SetFilePath(szPath);
  933. KIniFile cChannel;
  934. cChannel.WriteInteger("Channel", "Channel", this->m_dwTakeChannel);
  935. g_UnitePathAndName(szPath, CHAT_CHANNEL_INFO_FILE_NAME, szBuf);
  936. cChannel.Save(szBuf);
  937. }
  938. #endif
  939. #ifndef _SERVER
  940. //---------------------------------------------------------------------------
  941. // 功能:载入频道订阅信息
  942. // char *lpszName : 人名
  943. //---------------------------------------------------------------------------
  944. void KPlayerChat::LoadTakeChannelInfo(char *lpszName)
  945. {
  946. if (!lpszName || !lpszName[0])
  947. return;
  948. // 产生出相应路径
  949. char szPath[MAX_PATH], szBuf[MAX_PATH];
  950. DWORD dwTakeChannel;
  951. g_StrCpy(szPath, CHAT_PATH);
  952. g_StrCat(szPath, "\");
  953. g_StrCat(szPath, lpszName);
  954. g_CreatePath(szPath);
  955. // g_SetFilePath(szPath);
  956. this->SetTakeChannel(g_dwChannelOr[CHAT_CUR_CHANNEL_SCREEN]);
  957. KIniFile cChannel;
  958. g_UnitePathAndName(szPath, CHAT_CHANNEL_INFO_FILE_NAME, szBuf);
  959. if (!cChannel.Load(szBuf))
  960. {
  961. m_dwTakeChannel |= g_dwChannelOr[CHAT_CUR_CHANNEL_TEAM] | g_dwChannelOr[CHAT_CUR_CHANNEL_FACTION] | g_dwChannelOr[CHAT_CUR_CHANNEL_SCREENSINGLE];
  962. this->SaveTakeChannelInfo(lpszName);
  963. this->SendTakeChannel();
  964. return;
  965. }
  966. cChannel.GetInteger("Channel", "Channel", this->m_dwTakeChannel, (int*)&dwTakeChannel);
  967. this->SetTakeChannel(dwTakeChannel);
  968. this->SendTakeChannel();
  969. }
  970. #endif
  971. #ifndef _SERVER
  972. /*---------------------------------------------------------------------------
  973. ** 功能:判断某个ID的好友在哪个组里
  974. ** dwID 被判断的 id
  975. **  lpszName 本客户端玩家名字
  976. **  lpszGetName 被判断的 id 的名字
  977. **-------------------------------------------------------------------------*/
  978. int KPlayerChat::CheckTeamNo(char *lpszName, char *lpszGetName)
  979. {
  980. int i;
  981. if (!lpszName || !lpszName[0] || !lpszGetName || !lpszGetName[0])
  982. return -1;
  983. if (m_btIniLoadFlag == FALSE)
  984. {
  985. if (!lpszName || !lpszName[0])
  986. return -1;
  987. // 产生出相应路径
  988. char szPath[MAX_PATH], szBuf[MAX_PATH];
  989. g_StrCpy(szPath, CHAT_PATH);
  990. g_StrCat(szPath, "\");
  991. g_StrCat(szPath, lpszName);
  992. g_CreatePath(szPath);
  993. // g_SetFilePath(szPath);
  994. g_UnitePathAndName(szPath, CHAT_TEAM_INFO_FILE_NAME, szBuf);
  995. if ( !m_cTeamInfo.Load(szBuf) )
  996. {
  997. this->SaveTeamInfo(lpszName);
  998. // g_SetFilePath(szPath);
  999. m_cTeamInfo.Load(szBuf);
  1000. }
  1001. else
  1002. {
  1003. char szKey[32], szTemp[32];
  1004. strcpy(m_cFriendTeam[0].m_szTeamName, CHAT_TEAM_DEFAULT_NAME);
  1005. for (i = 1; i < MAX_FRIEND_TEAM; i++)
  1006. {
  1007. sprintf(szKey, "%d", i);
  1008. m_cTeamInfo.GetString("TeamName", szKey, "", szTemp, sizeof(szTemp));
  1009. if ( szTemp[0] )
  1010. {
  1011. strcpy(this->m_cFriendTeam[i].m_szTeamName, szTemp);
  1012. }
  1013. else
  1014. {
  1015. this->m_cFriendTeam[i].m_szTeamName[0] = 0;
  1016. }
  1017. }
  1018. }
  1019. m_btIniLoadFlag = TRUE;
  1020. }
  1021. char szKey[32], szTemp[32], szSect[64];
  1022. int nFriendNo, j;
  1023. for (i = 0; i < MAX_FRIEND_TEAM; i++)
  1024. {
  1025. sprintf(szKey, "%d", i);
  1026. m_cTeamInfo.GetString("TeamName", szKey, "", szTemp, sizeof(szTemp));
  1027. if ( !szTemp[0] )
  1028. continue;
  1029. sprintf(szSect, "T_%s", szTemp);
  1030. m_cTeamInfo.GetInteger(szSect, "FriendNo", 0, &nFriendNo);
  1031. for (j = 0; j < nFriendNo; j++)
  1032. {
  1033. sprintf(szKey, "%d", j);
  1034. m_cTeamInfo.GetString(szSect, szKey, "", szTemp, sizeof(szTemp));
  1035. if (strcmp(szTemp, lpszGetName) == 0)
  1036. return i;
  1037. }
  1038. }
  1039. return -1;
  1040. }
  1041. #endif
  1042. #ifndef _SERVER
  1043. //---------------------------------------------------------------------------
  1044. // 功能:载入组名(初始化的时候调用,其他时候不允许调用)
  1045. //---------------------------------------------------------------------------
  1046. void KPlayerChat::LoadTeamName(char *lpszPlayerName)
  1047. {
  1048. if (m_btIniLoadFlag)
  1049. return;
  1050. if (!lpszPlayerName || !lpszPlayerName[0])
  1051. return;
  1052. this->Release();
  1053. // 产生出相应路径
  1054. char szPath[MAX_PATH], szBuf[MAX_PATH];
  1055. KIniFile cIni;
  1056. g_StrCpy(szPath, CHAT_PATH);
  1057. g_StrCat(szPath, "\");
  1058. g_StrCat(szPath, lpszPlayerName);
  1059. g_CreatePath(szPath);
  1060. // g_SetFilePath(szPath);
  1061. g_UnitePathAndName(szPath, CHAT_TEAM_INFO_FILE_NAME, szBuf);
  1062. if (!cIni.Load(szBuf))
  1063. {
  1064. this->SaveTeamInfo(lpszPlayerName);
  1065. return;
  1066. }
  1067. char szKey[32], szTemp[32];
  1068. strcpy(m_cFriendTeam[0].m_szTeamName, CHAT_TEAM_DEFAULT_NAME);
  1069. for (int i = 1; i < MAX_FRIEND_TEAM; i++)
  1070. {
  1071. sprintf(szKey, "%d", i);
  1072. cIni.GetString("TeamName", szKey, "", szTemp, sizeof(szTemp));
  1073. if ( !szTemp[0] )
  1074. continue;
  1075. strcpy(this->m_cFriendTeam[i].m_szTeamName, szTemp);
  1076. }
  1077. }
  1078. #endif
  1079. #ifndef _SERVER
  1080. //---------------------------------------------------------------------------
  1081. // 功能:添加一个成员
  1082. //---------------------------------------------------------------------------
  1083. void KPlayerChat::AddOne(DWORD dwID, int nPlayerIdx, char *lpszName, int nTeamNo)
  1084. {
  1085. if (!lpszName || !lpszName[0])
  1086. return;
  1087. if (nTeamNo < 0 || nTeamNo >= MAX_FRIEND_TEAM)
  1088. return;
  1089. CChatFriend *pFriend;
  1090. pFriend = new CChatFriend;
  1091. pFriend->m_dwID = dwID;
  1092. pFriend->m_nPlayerIdx = nPlayerIdx;
  1093. g_StrCpy(pFriend->m_szName, lpszName);
  1094. m_cFriendTeam[nTeamNo].m_cEveryOne.AddTail(pFriend);
  1095. m_cFriendTeam[nTeamNo].m_nFriendNo++;
  1096. // 通知界面
  1097. // CoreDataChanged(GDCNI_CHAT_GROUP, 0, 0);
  1098. CoreDataChanged(GDCNI_CHAT_FRIEND, 0, nTeamNo);
  1099. }
  1100. #endif
  1101. #ifndef _SERVER
  1102. //---------------------------------------------------------------------------
  1103. // 功能:判断某个playeridx是否好友
  1104. //---------------------------------------------------------------------------
  1105. BOOL KPlayerChat::CheckIsFriend(int nPlayerIdx)
  1106. {
  1107. for (int i = 0; i < MAX_FRIEND_TEAM; i++)
  1108. {
  1109. if (m_cFriendTeam[i].m_nFriendNo == 0)
  1110. continue;
  1111. CChatFriend *pFriend;
  1112. pFriend = (CChatFriend*)m_cFriendTeam[i].m_cEveryOne.GetHead();
  1113. while (pFriend)
  1114. {
  1115. if (pFriend->m_nPlayerIdx == nPlayerIdx)
  1116. return TRUE;
  1117. pFriend = (CChatFriend*)pFriend->GetNext();
  1118. }
  1119. }
  1120. return FALSE;
  1121. }
  1122. #endif
  1123. #ifdef _SERVER
  1124. //---------------------------------------------------------------------------
  1125. // 功能:玩家登陆的时候从数据库获得数据时专用
  1126. // 参数:nSelfIdx 本玩家自己在Player中的位置 dwID  好友ID  lpszName  好友名字
  1127. //---------------------------------------------------------------------------
  1128. void KPlayerChat::DataBaseAddOne(int nSelfIdx, DWORD dwID, char *lpszName)
  1129. {
  1130. this->m_cFriendTeam[0].DataBaseAddOne(nSelfIdx, dwID, lpszName);
  1131. }
  1132. #endif
  1133. #ifdef _SERVER
  1134. //---------------------------------------------------------------------------
  1135. // 功能:添加好友数据
  1136. //---------------------------------------------------------------------------
  1137. void KPlayerChat::AddFriendData(int nSelfIdx, int nDestIdx)
  1138. {
  1139. if (this->CheckExist(Player[nDestIdx].m_dwID))
  1140. return;
  1141. CChatFriend *pFriend = NULL;
  1142. pFriend = new CChatFriend;
  1143. if ( !pFriend )
  1144. return;
  1145. pFriend->m_dwID = Player[nDestIdx].m_dwID;
  1146. pFriend->m_nPlayerIdx = nDestIdx;
  1147. g_StrCpy(pFriend->m_szName, Npc[Player[nDestIdx].m_nIndex].Name);
  1148. m_cFriendTeam[0].m_cEveryOne.AddTail(pFriend);
  1149. m_cFriendTeam[0].m_nFriendNo++;
  1150. CHAT_ADD_FRIEND_SYNC sAdd;
  1151. sAdd.ProtocolType = s2c_chataddfriend;
  1152. sAdd.m_dwID = Player[nDestIdx].m_dwID;
  1153. sAdd.m_nIdx = nDestIdx;
  1154. memset(sAdd.m_szName, 0, 32);
  1155. g_StrCpy(sAdd.m_szName, Npc[Player[nDestIdx].m_nIndex].Name);
  1156. g_pServer->PackDataToClient(Player[nSelfIdx].m_nNetConnectIdx, (BYTE*)&sAdd, sizeof(CHAT_ADD_FRIEND_SYNC));
  1157. }
  1158. #endif
  1159. #ifdef _SERVER
  1160. //---------------------------------------------------------------------------
  1161. // 功能:重新发送某个好友数据
  1162. //  dwID 好友 id   nPlayerIdx 玩家自己
  1163. //---------------------------------------------------------------------------
  1164. void KPlayerChat::ResendOneFriendData(DWORD dwID, int nPlayerIdx)
  1165. {
  1166. BOOL bFind = FALSE;
  1167. CChatFriend *pFriend;
  1168. pFriend = (CChatFriend*)m_cFriendTeam[0].m_cEveryOne.GetHead();
  1169. while (pFriend)
  1170. {
  1171. if (pFriend->m_dwID == dwID)
  1172. {
  1173. bFind = TRUE;
  1174. break;
  1175. }
  1176. pFriend = (CChatFriend*)pFriend->GetNext();
  1177. }
  1178. if ( !bFind )
  1179. return;
  1180. CHAT_ONE_FRIEND_DATA_SYNC sData;
  1181. sData.ProtocolType = s2c_chatonefrienddata;
  1182. sData.m_dwID = dwID;
  1183. sData.m_nPlayerIdx = pFriend->m_nPlayerIdx;
  1184. memset(sData.m_szName, 0, sizeof(sData.m_szName));
  1185. g_StrCpy(sData.m_szName, pFriend->m_szName);
  1186. g_pServer->PackDataToClient(Player[nPlayerIdx].m_nNetConnectIdx, (BYTE*)&sData, sizeof(CHAT_ONE_FRIEND_DATA_SYNC));
  1187. }
  1188. #endif
  1189. #ifdef _SERVER
  1190. //---------------------------------------------------------------------------
  1191. // 功能:玩家登录时加载数据库玩家好友数据完成后自动依次发送好友数据给客户端
  1192. //---------------------------------------------------------------------------
  1193. BOOL KPlayerChat::SyncFriendData(int nPlayerIdx, unsigned int &nParam)
  1194. {
  1195. BOOL bRet = FALSE;
  1196. if ( !m_nSyncState ) // 平时不做任何处理 m_nSyncState == 0
  1197. return TRUE;
  1198. if ( m_nSyncState == 1 ) // 玩家刚登录,发送不带名字的聊天好友数据
  1199. {
  1200. if ( !m_pStateSendPos )
  1201. {
  1202. m_nSyncState = 0;
  1203. nParam = 2;
  1204. return TRUE;
  1205. }
  1206. CHAT_LOGIN_FRIEND_NONAME_SYNC sFriend;
  1207. sFriend.ProtocolType = s2c_chatloginfriendnoname;
  1208. sFriend.m_dwID = m_pStateSendPos->m_dwID;
  1209. sFriend.m_nPlayerIdx = m_pStateSendPos->m_nPlayerIdx;
  1210. if (SUCCEEDED(g_pServer->PackDataToClient(Player[nPlayerIdx].m_nNetConnectIdx, (BYTE*)&sFriend, sizeof(CHAT_LOGIN_FRIEND_NONAME_SYNC))))
  1211. {
  1212. bRet = TRUE;
  1213. }
  1214. else
  1215. {
  1216. printf("player Packing friend sync data failed...n");
  1217. bRet = FALSE;
  1218. }
  1219. m_pStateSendPos = (CChatFriend*)m_pStateSendPos->GetNext();
  1220. return bRet;
  1221. }
  1222. if ( m_nSyncState == 2 ) // 玩家刚登录,发送带名字的聊天好友数据(玩家客户端没有好友分组和名字信息)
  1223. {
  1224. if ( !m_pStateSendPos )
  1225. {
  1226. m_nSyncState = 0;
  1227. nParam = 2;
  1228. return TRUE;
  1229. }
  1230. CHAT_LOGIN_FRIEND_NAME_SYNC sFriend;
  1231. sFriend.ProtocolType = s2c_chatloginfriendname;
  1232. sFriend.m_dwID = m_pStateSendPos->m_dwID;
  1233. sFriend.m_nPlayerIdx = m_pStateSendPos->m_nPlayerIdx;
  1234. g_StrCpy(sFriend.m_szName, m_pStateSendPos->m_szName);
  1235. sFriend.m_wLength = sizeof(CHAT_LOGIN_FRIEND_NAME_SYNC) - 1 - sizeof(sFriend.m_szName) + strlen(sFriend.m_szName);
  1236. if (SUCCEEDED(g_pServer->PackDataToClient(Player[nPlayerIdx].m_nNetConnectIdx, (BYTE*)&sFriend, sFriend.m_wLength + 1)))
  1237. {
  1238. bRet = TRUE;
  1239. }
  1240. else
  1241. {
  1242. printf("player Packing friend 2 sync data failed...n");
  1243. bRet = FALSE;
  1244. }
  1245. m_pStateSendPos = (CChatFriend*)m_pStateSendPos->GetNext();
  1246. return bRet;
  1247. }
  1248. return TRUE;
  1249. }
  1250. #endif
  1251. #ifdef _SERVER
  1252. //---------------------------------------------------------------------------
  1253. // 功能:玩家登录时加载数据库玩家好友数据完成后调用次方法开始发送给客户端好友数据
  1254. //---------------------------------------------------------------------------
  1255. void KPlayerChat::StartSendFriendData()
  1256. {
  1257. this->SetTakeChannel(g_dwChannelOr[CHAT_CUR_CHANNEL_SCREEN]);
  1258. m_pStateSendPos = (CChatFriend*)m_cFriendTeam[0].m_cEveryOne.GetHead();
  1259. m_nSyncState = 2;
  1260. }
  1261. #endif
  1262. #ifdef _SERVER
  1263. //---------------------------------------------------------------------------
  1264. // 功能:删除某个好友数据(会通知对方相应处理)
  1265. //---------------------------------------------------------------------------
  1266. void KPlayerChat::DeleteFriend(DWORD dwID, DWORD dwSelfID)
  1267. {
  1268. CChatFriend *pFriend;
  1269. pFriend = (CChatFriend*)m_cFriendTeam[0].m_cEveryOne.GetHead();
  1270. while (pFriend)
  1271. {
  1272. if (pFriend->m_dwID == dwID)
  1273. {
  1274. pFriend->Remove();
  1275. m_cFriendTeam[0].m_nFriendNo--;
  1276. // 通知被删除方执行相应处理
  1277. if (pFriend->m_nPlayerIdx)
  1278. { // 如果对方在线,id 正确
  1279. if (pFriend->m_nPlayerIdx < MAX_PLAYER && Player[pFriend->m_nPlayerIdx].m_nIndex && Player[pFriend->m_nPlayerIdx].m_dwID == dwID)
  1280. {
  1281. Player[pFriend->m_nPlayerIdx].m_cChat.DeleteFriendData(dwSelfID, pFriend->m_nPlayerIdx);
  1282. }
  1283. }
  1284. delete pFriend;
  1285. return;
  1286. }
  1287. pFriend = (CChatFriend*)pFriend->GetNext();
  1288. }
  1289. }
  1290. #endif
  1291. #ifdef _SERVER
  1292. //---------------------------------------------------------------------------
  1293. // 功能:删除某个好友数据(会通知自己客户端)
  1294. //---------------------------------------------------------------------------
  1295. void KPlayerChat::DeleteFriendData(DWORD dwID, int nSelfIndex)
  1296. {
  1297. CChatFriend *pFriend;
  1298. pFriend = (CChatFriend*)this->m_cFriendTeam[0].m_cEveryOne.GetHead();
  1299. while (pFriend)
  1300. {
  1301. if (pFriend->m_dwID == dwID)
  1302. {
  1303. pFriend->Remove();
  1304. delete pFriend;
  1305. m_cFriendTeam[0].m_nFriendNo--;
  1306. // 通知客户端
  1307. CHAT_DELETE_FRIEND_SYNC sDelete;
  1308. sDelete.ProtocolType = s2c_chatdeletefriend;
  1309. sDelete.m_dwID = dwID;
  1310. g_pServer->PackDataToClient(Player[nSelfIndex].m_nNetConnectIdx, (BYTE*)&sDelete, sizeof(CHAT_DELETE_FRIEND_SYNC));
  1311. return;
  1312. }
  1313. pFriend = (CChatFriend*)pFriend->GetNext();
  1314. }
  1315. }
  1316. #endif
  1317. #ifdef _SERVER
  1318. //---------------------------------------------------------------------------
  1319. // 功能:再次删除某好友
  1320. //---------------------------------------------------------------------------
  1321. void KPlayerChat::RedeleteFriend(DWORD dwID, int nSelfIndex)
  1322. {
  1323. if( !CheckExist(dwID) )
  1324. {
  1325. int nIdx;
  1326. nIdx = PlayerSet.FindSame(dwID);
  1327. if (nIdx > 0)
  1328. Player[nIdx].m_cChat.DeleteFriendData(Player[nSelfIndex].m_dwID, nIdx);
  1329. }
  1330. }
  1331. #endif
  1332. #ifdef _SERVER
  1333. //---------------------------------------------------------------------------
  1334. // 功能:本玩家下线
  1335. //---------------------------------------------------------------------------
  1336. void KPlayerChat::OffLine(DWORD dwSelfID)
  1337. {
  1338. CChatFriend *pNode;
  1339. pNode = (CChatFriend*)m_cFriendTeam[0].m_cEveryOne.GetHead();
  1340. while (pNode)
  1341. {
  1342. if (pNode->m_nPlayerIdx)
  1343. {
  1344. Player[pNode->m_nPlayerIdx].m_cChat.GetMsgOffLine(dwSelfID, pNode->m_nPlayerIdx);
  1345. }
  1346. pNode = (CChatFriend*)pNode->GetNext();
  1347. }
  1348. }
  1349. #endif
  1350. #ifdef _SERVER
  1351. //---------------------------------------------------------------------------
  1352. // 功能:得到通知有好友下线
  1353. //---------------------------------------------------------------------------
  1354. void KPlayerChat::GetMsgOffLine(DWORD dwID, int nSelfIdx)
  1355. {
  1356. CChatFriend *pNode;
  1357. pNode = (CChatFriend*)m_cFriendTeam[0].m_cEveryOne.GetHead();
  1358. while (pNode)
  1359. {
  1360. if (pNode->m_nPlayerIdx && pNode->m_dwID == dwID)
  1361. {
  1362. pNode->m_nPlayerIdx = 0;
  1363. // 通知客户端
  1364. CHAT_FRIEND_OFFLINE_SYNC sSync;
  1365. sSync.ProtocolType = s2c_chatfriendoffline;
  1366. sSync.m_dwID = dwID;
  1367. g_pServer->PackDataToClient(Player[nSelfIdx].m_nNetConnectIdx, (BYTE*)&sSync, sizeof(CHAT_FRIEND_OFFLINE_SYNC));
  1368. return;
  1369. }
  1370. pNode = (CChatFriend*)pNode->GetNext();
  1371. }
  1372. }
  1373. #endif
  1374. #ifdef _SERVER
  1375. //---------------------------------------------------------------------------
  1376. // 功能:聊天时间计数加一
  1377. //---------------------------------------------------------------------------
  1378. void KPlayerChat::TimerAdd()
  1379. {
  1380. this->m_nTimer++;
  1381. }
  1382. #endif
  1383. #ifndef _SERVER
  1384. //---------------------------------------------------------------------------
  1385. // 功能:添加组,返回第几组,if return value == -1 失败
  1386. //---------------------------------------------------------------------------
  1387. int KPlayerChat::AddTeam(char *lpszPlayerName, char *lpszTeamName)
  1388. {
  1389. if (!lpszPlayerName || !lpszPlayerName[0])
  1390. return -1;
  1391. if (!lpszTeamName || !lpszTeamName[0])
  1392. return -1;
  1393. int i;
  1394. // 判断是否有同名组
  1395. for (i = 0; i < MAX_FRIEND_TEAM; i++)
  1396. {
  1397. if (strcmp(lpszTeamName, m_cFriendTeam[i].m_szTeamName) == 0)
  1398. {
  1399. KSystemMessage sMsg;
  1400. sprintf(sMsg.szMessage, MSG_CHAT_CREATE_TEAM_FAIL1);
  1401. sMsg.eType = SMT_NORMAL;
  1402. sMsg.byConfirmType = SMCT_NONE;
  1403. sMsg.byPriority = 0;
  1404. sMsg.byParamSize = 0;
  1405. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1406. sprintf(sMsg.szMessage, MSG_CHAT_CREATE_TEAM_FAIL2);
  1407. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1408. return -1;
  1409. }
  1410. }
  1411. // 第 0 组是默认拥有的组
  1412. for (i = 1; i < MAX_FRIEND_TEAM; i++)
  1413. {
  1414. if ( !m_cFriendTeam[i].m_szTeamName[0] && m_cFriendTeam[i].m_nFriendNo == 0)
  1415. {
  1416. g_StrCpy(m_cFriendTeam[i].m_szTeamName, lpszTeamName);
  1417. SaveTeamInfo(lpszPlayerName);
  1418. return i;
  1419. }
  1420. }
  1421. KSystemMessage sMsg;
  1422. sprintf(sMsg.szMessage, MSG_CHAT_CREATE_TEAM_FAIL1);
  1423. sMsg.eType = SMT_NORMAL;
  1424. sMsg.byConfirmType = SMCT_NONE;
  1425. sMsg.byPriority = 0;
  1426. sMsg.byParamSize = 0;
  1427. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1428. sprintf(sMsg.szMessage, MSG_CHAT_CREATE_TEAM_FAIL3);
  1429. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1430. return -1;
  1431. }
  1432. #endif
  1433. #ifndef _SERVER
  1434. //---------------------------------------------------------------------------
  1435. // 功能:组改名
  1436. //---------------------------------------------------------------------------
  1437. BOOL KPlayerChat::RenameTeam(int nTeamNo, char *lpszTeamName, char *lpszPlayerName)
  1438. {
  1439. if (!lpszPlayerName || !lpszPlayerName[0])
  1440. return FALSE;
  1441. if (!lpszTeamName || !lpszTeamName[0])
  1442. return FALSE;
  1443. if (nTeamNo < 1 || nTeamNo >= MAX_FRIEND_TEAM)
  1444. return FALSE;
  1445. if (!m_cFriendTeam[nTeamNo].m_szTeamName[0])
  1446. return FALSE;
  1447. if (strlen(lpszTeamName) >= sizeof(m_cFriendTeam[nTeamNo].m_szTeamName))
  1448. return FALSE;
  1449. int i;
  1450. // 判断是否有同名组
  1451. for (i = 0; i < MAX_FRIEND_TEAM; i++)
  1452. {
  1453. if (i == nTeamNo)
  1454. continue;
  1455. if (strcmp(lpszTeamName, m_cFriendTeam[i].m_szTeamName) == 0)
  1456. {
  1457. KSystemMessage sMsg;
  1458. sprintf(sMsg.szMessage, MSG_CHAT_RENAME_TEAM_FAIL);
  1459. sMsg.eType = SMT_NORMAL;
  1460. sMsg.byConfirmType = SMCT_NONE;
  1461. sMsg.byPriority = 0;
  1462. sMsg.byParamSize = 0;
  1463. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1464. sprintf(sMsg.szMessage, MSG_CHAT_CREATE_TEAM_FAIL2);
  1465. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1466. return FALSE;
  1467. }
  1468. }
  1469. g_StrCpy(m_cFriendTeam[nTeamNo].m_szTeamName, lpszTeamName);
  1470. SaveTeamInfo(lpszPlayerName);
  1471. return TRUE;
  1472. }
  1473. #endif
  1474. #ifndef _SERVER
  1475. //---------------------------------------------------------------------------
  1476. // 功能:删除组,返回成功与否
  1477. //---------------------------------------------------------------------------
  1478. BOOL KPlayerChat::DeleteTeam(int nTeamNo, char *lpszPlayerName)
  1479. {
  1480. if (!lpszPlayerName || !lpszPlayerName[0])
  1481. return FALSE;
  1482. if (nTeamNo == 0)
  1483. {
  1484. KSystemMessage sMsg;
  1485. sprintf(sMsg.szMessage, MSG_CHAT_DELETE_TEAM_FAIL1);
  1486. sMsg.eType = SMT_NORMAL;
  1487. sMsg.byConfirmType = SMCT_NONE;
  1488. sMsg.byPriority = 0;
  1489. sMsg.byParamSize = 0;
  1490. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1491. sprintf(sMsg.szMessage, MSG_CHAT_DELETE_TEAM_FAIL2);
  1492. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1493. return FALSE;
  1494. }
  1495. if (nTeamNo < 1 || nTeamNo >= MAX_FRIEND_TEAM)
  1496. return FALSE;
  1497. if (!this->m_cFriendTeam[nTeamNo].m_szTeamName[0])
  1498. return FALSE;
  1499. CChatFriend *pFriend;
  1500. pFriend = (CChatFriend*)m_cFriendTeam[nTeamNo].m_cEveryOne.GetHead();
  1501. while (pFriend)
  1502. {
  1503. m_cFriendTeam[nTeamNo].m_cEveryOne.RemoveHead();
  1504. m_cFriendTeam[0].m_cEveryOne.AddTail(pFriend);
  1505. m_cFriendTeam[0].m_nFriendNo++;
  1506. pFriend = (CChatFriend*)m_cFriendTeam[nTeamNo].m_cEveryOne.GetHead();
  1507. }
  1508. m_cFriendTeam[nTeamNo].m_szTeamName[0] = 0;
  1509. m_cFriendTeam[nTeamNo].m_nFriendNo = 0;
  1510. SaveTeamInfo(lpszPlayerName);
  1511. return TRUE;
  1512. }
  1513. #endif
  1514. #ifndef _SERVER
  1515. //---------------------------------------------------------------------------
  1516. // 功能:把一个好友从一个组移动到另一个组
  1517. //---------------------------------------------------------------------------
  1518. BOOL KPlayerChat::OneFriendChangeTeam(DWORD dwID, int nSrcTeam, int nDestTeam)
  1519. {
  1520. if (nSrcTeam < 0 || nSrcTeam >= MAX_FRIEND_TEAM)
  1521. return FALSE;
  1522. if (nDestTeam < 0 || nDestTeam >= MAX_FRIEND_TEAM)
  1523. return FALSE;
  1524. if ( !m_cFriendTeam[nDestTeam].m_szTeamName[0] )
  1525. return FALSE;
  1526. CChatFriend *pFriend;
  1527. pFriend = (CChatFriend*)m_cFriendTeam[nSrcTeam].m_cEveryOne.GetHead();
  1528. while (pFriend)
  1529. {
  1530. if (pFriend->m_dwID == dwID)
  1531. {
  1532. pFriend->Remove();
  1533. m_cFriendTeam[nSrcTeam].m_nFriendNo--;
  1534. m_cFriendTeam[nDestTeam].m_cEveryOne.AddTail(pFriend);
  1535. m_cFriendTeam[nDestTeam].m_nFriendNo++;
  1536. this->SaveTeamInfo(Npc[Player[CLIENT_PLAYER_INDEX].m_nIndex].Name);
  1537. return TRUE;
  1538. }
  1539. pFriend = (CChatFriend*)pFriend->GetNext();
  1540. }
  1541. return FALSE;
  1542. }
  1543. #endif
  1544. #ifndef _SERVER
  1545. //---------------------------------------------------------------------------
  1546. // 功能:得到通知有好友下线
  1547. //---------------------------------------------------------------------------
  1548. void KPlayerChat::GetMsgOffLine(DWORD dwID)
  1549. {
  1550. CChatFriend *pFriend;
  1551. for (int i = 0; i < MAX_FRIEND_TEAM; i++)
  1552. {
  1553. pFriend = (CChatFriend*)this->m_cFriendTeam[i].m_cEveryOne.GetHead();
  1554. while (pFriend)
  1555. {
  1556. if (pFriend->m_dwID == dwID)
  1557. {
  1558. pFriend->m_nPlayerIdx = 0;
  1559. // 通知界面有好友下线
  1560. KUiPlayerItem sPlayer;
  1561. strcpy(sPlayer.Name, pFriend->m_szName);
  1562. sPlayer.uId = dwID;
  1563. sPlayer.nIndex = 0;
  1564. sPlayer.nData = CHAT_S_DISCONNECT;
  1565. CoreDataChanged(GDCNI_CHAT_FRIEND_STATUS, (unsigned int)&sPlayer, i);
  1566. KSystemMessage sMsg;
  1567. sprintf(sMsg.szMessage, MSG_CHAT_FRIEND_OFFLINE, pFriend->m_szName);
  1568. sMsg.eType = SMT_NORMAL;
  1569. sMsg.byConfirmType = SMCT_NONE;
  1570. sMsg.byPriority = 0;
  1571. sMsg.byParamSize = 0;
  1572. CoreDataChanged(GDCNI_SYSTEM_MESSAGE, (unsigned int)&sMsg, 0);
  1573. return;
  1574. }
  1575. pFriend = (CChatFriend*)pFriend->GetNext();
  1576. }
  1577. }
  1578. }
  1579. #endif
  1580. #ifndef _SERVER
  1581. //---------------------------------------------------------------------------
  1582. // 功能:判断是否订阅了某个频道
  1583. //---------------------------------------------------------------------------
  1584. BOOL KPlayerChat::CheckTakeChannel(int nChannelNo)
  1585. {
  1586. if (nChannelNo < CHAT_CUR_CHANNEL_NONE || nChannelNo >= CHAT_CUR_CHANNEL_NUM)
  1587. return FALSE;
  1588. return (this->m_dwTakeChannel & g_dwChannelOr[nChannelNo]);
  1589. }
  1590. #endif
  1591. #ifndef _SERVER
  1592. //---------------------------------------------------------------------------
  1593. // 功能:客户端申请删除某好友
  1594. //---------------------------------------------------------------------------
  1595. void KPlayerChat::ApplyDeleteFriend(DWORD dwID, int nTeamNo, char *lpszSelfName)
  1596. {
  1597. if (!lpszSelfName || !lpszSelfName[0])
  1598. return;
  1599. if (nTeamNo < 0 || nTeamNo >= MAX_FRIEND_TEAM)
  1600. return;
  1601. CChatFriend *pFriend;
  1602. pFriend = (CChatFriend*)m_cFriendTeam[nTeamNo].m_cEveryOne.GetHead();
  1603. while (pFriend)
  1604. {
  1605. if (pFriend->m_dwID == dwID)
  1606. {
  1607. pFriend->Remove();
  1608. delete pFriend;
  1609. m_cFriendTeam[nTeamNo].m_nFriendNo--;
  1610. SaveTeamInfo(lpszSelfName);
  1611. CHAT_DELETE_FRIEND_COMMAND sDelete;
  1612. sDelete.ProtocolType = c2s_chatdeletefriend;
  1613. sDelete.m_dwID = dwID;
  1614. if (g_pClient)
  1615. g_pClient->SendPackToServer(&sDelete, sizeof(CHAT_DELETE_FRIEND_COMMAND));
  1616. // CoreDataChanged(GDCNI_CHAT_GROUP, 0, 0);
  1617. CoreDataChanged(GDCNI_CHAT_FRIEND, 0, nTeamNo);
  1618. return;
  1619. }
  1620. pFriend = (CChatFriend*)pFriend->GetNext();
  1621. }
  1622. }
  1623. #endif
  1624. BOOL KPlayerChat::CheckTalkChannel(int nChannel)
  1625. {
  1626. if (nChannel <= CHAT_CUR_CHANNEL_NONE || nChannel >= CHAT_CUR_CHANNEL_NUM)
  1627. return FALSE;
  1628. return (this->m_dwTakeChannel & g_dwChannelOr[nChannel]);
  1629. }
  1630. //---------------------------------------------------------------------------
  1631. // 功能:发送系统消息
  1632. //  nType == 0 给全体玩家发送 nType == 1 给某个特定玩家发送
  1633. //  dwTargetID:  if (nType == 1) 目标玩家在 player 数组中的位置
  1634. //  lpszSendName:  发送者名字,可能是 系统消息、通知、警告、注意 等等 长度不超过 32
  1635. //  lpszSentence:  需要发送的语句
  1636. //  nSentenceLength:  需要发送语句的长度
  1637. //---------------------------------------------------------------------------
  1638. #ifdef _SERVER
  1639. void KPlayerChat::SendSystemInfo(int nType, int nTargetIdx, char *lpszSendName, char *lpszSentence, int nSentenceLength)
  1640. {
  1641. if (!lpszSendName || !lpszSentence)
  1642. return;
  1643. if (nSentenceLength >= MAX_SENTENCE_LENGTH)
  1644. nSentenceLength = MAX_SENTENCE_LENGTH;
  1645. BOOL bAll = nType == 0;
  1646. size_t chatsize = sizeof(CHAT_CHANNELCHAT_SYNC) + nSentenceLength;
  1647. size_t pckgsize = sizeof(tagExtendProtoHeader) + chatsize;
  1648. #ifdef WIN32
  1649. tagExtendProtoHeader* pExHeader = (tagExtendProtoHeader*)_alloca(pckgsize);
  1650. #else
  1651. tagExtendProtoHeader* pExHeader = (tagExtendProtoHeader*)(new char[pckgsize]);
  1652. #endif
  1653. pExHeader->ProtocolType = s2c_extendchat;
  1654. pExHeader->wLength = pckgsize - 1;
  1655. CHAT_CHANNELCHAT_SYNC* pCccSync= (CHAT_CHANNELCHAT_SYNC*)(pExHeader + 1);
  1656. pCccSync->ProtocolType = chat_channelchat;
  1657. pCccSync->wSize = chatsize - 1;
  1658. pCccSync->packageID = -1;
  1659. strncpy(pCccSync->someone, lpszSendName, _NAME_LEN - 1); // 可能需要根据玩家身份改动
  1660. pCccSync->channelid = -1;
  1661. pCccSync->sentlen = nSentenceLength;
  1662. memcpy(pCccSync + 1, lpszSentence, nSentenceLength);
  1663. if (bAll) // 给全体玩家发送
  1664. {
  1665. int nTargetIdx;
  1666. nTargetIdx = PlayerSet.GetFirstPlayer();
  1667. while (nTargetIdx)
  1668. {
  1669. g_pServer->PackDataToClient(Player[nTargetIdx].m_nNetConnectIdx, pExHeader, pckgsize);
  1670. nTargetIdx = PlayerSet.GetNextPlayer();
  1671. }
  1672. }
  1673. else // 给某个特定玩家发送
  1674. {
  1675. if (nTargetIdx <= 0)
  1676. {
  1677. #ifndef WIN32
  1678. if (pExHeader)
  1679. delete ((char*)pExHeader);
  1680. #endif
  1681. return;
  1682. }
  1683. g_pServer->PackDataToClient(Player[nTargetIdx].m_nNetConnectIdx, pExHeader, pckgsize);
  1684. }
  1685. #ifndef WIN32
  1686. if (pExHeader)
  1687. delete ((char*)pExHeader);
  1688. #endif
  1689. return;
  1690. /*
  1691. if (!lpszSendName || !lpszSentence)
  1692. return;
  1693. if (nSentenceLength >= MAX_SENTENCE_LENGTH)
  1694. nSentenceLength = MAX_SENTENCE_LENGTH;
  1695. if (nType == 0) // 给全体玩家发送
  1696. {
  1697. PLAYER_SEND_CHAT_SYNC sChat;
  1698. sChat.ProtocolType = s2c_playersendchat;
  1699. sChat.m_btCurChannel = CHAT_CUR_CHANNEL_SYSTEM;
  1700. sChat.m_dwSourceID = 0; // 发送者的player id 可能需要根据玩家身份改动
  1701. sChat.m_btNameLen = strlen(lpszSendName);
  1702. if (sChat.m_btNameLen >= 32)
  1703. sChat.m_btNameLen = 31;
  1704. if (lpszPrefix && nPrefixLen > 0)
  1705. {
  1706. sChat.m_btChatPrefixLen = nPrefixLen;
  1707. if (sChat.m_btChatPrefixLen >= CHAT_MSG_PREFIX_MAX_LEN)
  1708. sChat.m_btChatPrefixLen = CHAT_MSG_PREFIX_MAX_LEN - 1;
  1709. }
  1710. else
  1711. {
  1712. sChat.m_btChatPrefixLen = 0;
  1713. }
  1714. sChat.m_wSentenceLen = nSentenceLength;
  1715. sChat.m_wLength = sizeof(PLAYER_SEND_CHAT_SYNC) - 1 - sizeof(sChat.m_szSentence) + sChat.m_btNameLen + sChat.m_btChatPrefixLen + sChat.m_wSentenceLen;
  1716. memcpy(&sChat.m_szSentence[0], lpszSendName, sChat.m_btNameLen); // 可能需要根据玩家身份改动
  1717. if (lpszPrefix)
  1718. memcpy(&sChat.m_szSentence[sChat.m_btNameLen], lpszPrefix, sChat.m_btChatPrefixLen);
  1719. memcpy(&sChat.m_szSentence[sChat.m_btNameLen + sChat.m_btChatPrefixLen], lpszSentence, sChat.m_wSentenceLen); // 可能需要根据玩家身份改动
  1720. int nTargetIdx;
  1721. nTargetIdx = PlayerSet.GetFirstPlayer();
  1722. while (nTargetIdx)
  1723. {
  1724. g_pServer->PackDataToClient(Player[nTargetIdx].m_nNetConnectIdx, (BYTE*)&sChat, sChat.m_wLength + 1);
  1725. nTargetIdx = PlayerSet.GetNextPlayer();
  1726. }
  1727. }
  1728. else // 给某个特定玩家发送
  1729. {
  1730. int nIdx;
  1731. nIdx = nTargetIdx;
  1732. // nIdx = PlayerSet.FindSame(dwTargetID);
  1733. if (nIdx <= 0)
  1734. return;
  1735. PLAYER_SEND_CHAT_SYNC sChat;
  1736. sChat.ProtocolType = s2c_playersendchat;
  1737. sChat.m_btCurChannel = CHAT_CUR_CHANNEL_SYSTEM;
  1738. sChat.m_dwSourceID = 0; // 发送者的player id 可能需要根据玩家身份改动
  1739. sChat.m_btNameLen = strlen(lpszSendName);
  1740. if (sChat.m_btNameLen >= 32)
  1741. sChat.m_btNameLen = 31;
  1742. if (lpszPrefix && nPrefixLen > 0)
  1743. {
  1744. sChat.m_btChatPrefixLen = nPrefixLen;
  1745. if (sChat.m_btChatPrefixLen >= CHAT_MSG_PREFIX_MAX_LEN)
  1746. sChat.m_btChatPrefixLen = CHAT_MSG_PREFIX_MAX_LEN - 1;
  1747. }
  1748. else
  1749. {
  1750. sChat.m_btChatPrefixLen = 0;
  1751. }
  1752. sChat.m_wSentenceLen = nSentenceLength;
  1753. sChat.m_wLength = sizeof(PLAYER_SEND_CHAT_SYNC) - 1 - sizeof(sChat.m_szSentence) + sChat.m_btNameLen + sChat.m_btChatPrefixLen + sChat.m_wSentenceLen;
  1754. memcpy(&sChat.m_szSentence[0], lpszSendName, sChat.m_btNameLen); // 可能需要根据玩家身份改动
  1755. if (lpszPrefix)
  1756. memcpy(&sChat.m_szSentence[sChat.m_btNameLen], lpszPrefix, sChat.m_btChatPrefixLen);
  1757. memcpy(&sChat.m_szSentence[sChat.m_btNameLen + sChat.m_btChatPrefixLen], lpszSentence, sChat.m_wSentenceLen); // 可能需要根据玩家身份改动
  1758. g_pServer->PackDataToClient(Player[nIdx].m_nNetConnectIdx, (BYTE*)&sChat, sChat.m_wLength + 1);
  1759. }
  1760. */
  1761. }
  1762. #endif
  1763. #ifdef _SERVER
  1764. void KPlayerChat::SendGlobalSystemInfo(char *lpszSendName, char *lpszSentence, int nSentenceLength)
  1765. {
  1766. if (!lpszSendName || !lpszSentence)
  1767. return;
  1768. if (nSentenceLength >= MAX_SENTENCE_LENGTH)
  1769. nSentenceLength = MAX_SENTENCE_LENGTH;
  1770. size_t chatsize = sizeof(CHAT_CHANNELCHAT_SYNC) + nSentenceLength;
  1771. size_t pckgsize = sizeof(tagExtendProtoHeader) + chatsize;
  1772. #ifdef WIN32
  1773. tagExtendProtoHeader* pExHeader = (tagExtendProtoHeader*)_alloca(pckgsize);
  1774. #else
  1775. tagExtendProtoHeader* pExHeader = (tagExtendProtoHeader*)(new char[pckgsize]);
  1776. #endif
  1777. pExHeader->ProtocolType = s2c_extendchat;
  1778. pExHeader->wLength = pckgsize - 1;
  1779. CHAT_CHANNELCHAT_SYNC* pCccSync= (CHAT_CHANNELCHAT_SYNC*)(pExHeader + 1);
  1780. pCccSync->ProtocolType = chat_channelchat;
  1781. pCccSync->wSize = chatsize - 1;
  1782. pCccSync->packageID = -1;
  1783. strncpy(pCccSync->someone, lpszSendName, _NAME_LEN - 1); // 可能需要根据玩家身份改动
  1784. pCccSync->channelid = -1;
  1785. pCccSync->sentlen = nSentenceLength;
  1786. memcpy(pCccSync + 1, lpszSentence, nSentenceLength);
  1787. g_NewProtocolProcess.BroadcastGlobal(pExHeader, pckgsize);
  1788. #ifndef WIN32
  1789. if (pExHeader)
  1790. delete ((char*)pExHeader);
  1791. #endif
  1792. }
  1793. #endif
  1794. #ifdef _SERVER
  1795. void KPlayerChat::SendInfoToGM(char *lpszAccName, char *lpszRoleName, char *lpszSentence, int nSentenceLength)
  1796. {
  1797. if (!lpszAccName ||
  1798. !lpszRoleName ||
  1799. !lpszSentence)
  1800. return;
  1801. if (nSentenceLength >= MAX_SENTENCE_LENGTH)
  1802. nSentenceLength = MAX_SENTENCE_LENGTH;
  1803. size_t chatsize = sizeof(CHAT_MSG_EX) + nSentenceLength;
  1804. size_t pckgsize = sizeof(RELAY_ASKWAY_DATA) + chatsize;
  1805. #ifdef WIN32
  1806. RELAY_ASKWAY_DATA* pExHeader = (RELAY_ASKWAY_DATA*)_alloca(pckgsize);
  1807. #else
  1808. RELAY_ASKWAY_DATA* pExHeader = (RELAY_ASKWAY_DATA*)(new char[pckgsize]);
  1809. #endif
  1810. pExHeader->ProtocolFamily = pf_relay;
  1811. pExHeader->ProtocolID = relay_c2c_askwaydata;
  1812. pExHeader->nFromIP = 0;
  1813. pExHeader->nFromRelayID = 0;
  1814. pExHeader->seekRelayCount = 0;
  1815. pExHeader->seekMethod = rm_gm;
  1816. pExHeader->wMethodDataLength = 0;
  1817. pExHeader->routeDateLength = chatsize;
  1818. CHAT_MSG_EX* pChatMsgEx= (CHAT_MSG_EX*)(pExHeader + 1);
  1819. pChatMsgEx->ProtocolFamily = pf_playercommunity;
  1820. pChatMsgEx->ProtocolID = playercomm_channelchat;
  1821. strcpy(pChatMsgEx->m_szSourceName, lpszRoleName);
  1822. strcpy(pChatMsgEx->m_szAccountName, lpszAccName);
  1823. pChatMsgEx->SentenceLength = nSentenceLength;
  1824. memcpy(pChatMsgEx + 1, lpszSentence, nSentenceLength);
  1825. g_NewProtocolProcess.PushMsgInTransfer(pExHeader, pckgsize);
  1826. #ifndef WIN32
  1827. if (pExHeader)
  1828. delete ((char*)pExHeader);
  1829. #endif
  1830. }
  1831. #endif
  1832. #ifdef _SERVER
  1833. void KPlayerChat::SendInfoToIP(DWORD nIP, DWORD nID, char *lpszAccName, char *lpszRoleName, char *lpszSentence, int nSentenceLength)
  1834. {
  1835. if (!lpszAccName ||
  1836. !lpszRoleName ||
  1837. !lpszSentence)
  1838. return;
  1839. if (nSentenceLength >= MAX_SENTENCE_LENGTH)
  1840. nSentenceLength = MAX_SENTENCE_LENGTH;
  1841. size_t chatsize = sizeof(CHAT_MSG_EX) + nSentenceLength;
  1842. size_t pckgsize = sizeof(RELAY_DATA) + chatsize;
  1843. #ifdef WIN32
  1844. RELAY_DATA* pExHeader = (RELAY_DATA*)_alloca(pckgsize);
  1845. #else
  1846. RELAY_DATA* pExHeader = (RELAY_DATA*)(new char[pckgsize]);
  1847. #endif
  1848. pExHeader->ProtocolFamily = pf_relay;
  1849. pExHeader->ProtocolID = relay_c2c_data;
  1850. pExHeader->nToIP = nIP;
  1851. pExHeader->nToRelayID = nID;
  1852. pExHeader->nFromIP = 0;
  1853. pExHeader->nFromRelayID = 0;
  1854. pExHeader->routeDateLength = chatsize;
  1855. CHAT_MSG_EX* pChatMsgEx= (CHAT_MSG_EX*)(pExHeader + 1);
  1856. pChatMsgEx->ProtocolFamily = pf_playercommunity;
  1857. pChatMsgEx->ProtocolID = playercomm_channelchat;
  1858. strcpy(pChatMsgEx->m_szSourceName, lpszRoleName);
  1859. strcpy(pChatMsgEx->m_szAccountName, lpszAccName);
  1860. pChatMsgEx->SentenceLength = nSentenceLength;
  1861. memcpy(pChatMsgEx + 1, lpszSentence, nSentenceLength);
  1862. g_NewProtocolProcess.PushMsgInTransfer(pExHeader, pckgsize);
  1863. #ifndef WIN32
  1864. if (pExHeader)
  1865. delete ((char*)pExHeader);
  1866. #endif
  1867. }
  1868. #endif
  1869. #ifdef _SERVER
  1870. #define BROTHER_UNITNAME "亲人n"
  1871. void KPlayerChat::MakeBrother(const STRINGLIST& brothers)
  1872. {
  1873. if (brothers.size() == 0)
  1874. return;
  1875. static const size_t max_packagesize = 1000;
  1876. char buffer[max_packagesize]; //max package size
  1877. size_t maxsize = max_packagesize - 1; //留个0的位置
  1878. size_t basesize = sizeof(FRIEND_ASSOCIATEBEVY);
  1879. FRIEND_ASSOCIATEBEVY* pGf = (FRIEND_ASSOCIATEBEVY*)(buffer);
  1880. pGf->ProtocolFamily = pf_friend;
  1881. pGf->ProtocolID = friend_c2s_associatebevy;
  1882. int nG = strlen(BROTHER_UNITNAME) + 1;
  1883. strcpy(buffer + basesize, BROTHER_UNITNAME);
  1884. basesize += nG;
  1885. size_t cursor = basesize;
  1886. for (STRINGLIST::const_iterator itFriend = brothers.begin(); itFriend != brothers.end(); itFriend++)
  1887. {
  1888. std::string dst = *itFriend;
  1889. size_t appendsize = dst.size() + 1;
  1890. if (cursor + appendsize > maxsize)
  1891. {
  1892. buffer[cursor++] = specOver; //加个结尾,发走
  1893. g_NewProtocolProcess.PushMsgInTong(buffer, cursor);
  1894. cursor = basesize; //从头开始
  1895. }
  1896. strcpy(buffer + cursor, dst.c_str());
  1897. cursor += appendsize;
  1898. }
  1899. if (cursor > basesize)
  1900. {
  1901. buffer[cursor++] = specOver;
  1902. g_NewProtocolProcess.PushMsgInTong(buffer, cursor);
  1903. }
  1904. }
  1905. #endif
  1906. #ifdef _SERVER
  1907. #define ENEMY_UNITNAME  "仇人n"
  1908. void KPlayerChat::MakeEnemy(char* szPlayer, char* szEnemy)
  1909. {
  1910. if (!szPlayer || szPlayer[0] == 0 ||
  1911. !szEnemy || szEnemy[0] == 0)
  1912. return;
  1913. int nG = strlen(ENEMY_UNITNAME) + 1;
  1914. int nP = strlen(szPlayer) + 1;
  1915. int nE = strlen(szEnemy) + 1;
  1916. size_t fsize = sizeof(FRIEND_ASSOCIATE) + nG + nP + nE;
  1917. #ifdef WIN32
  1918. FRIEND_ASSOCIATE* pCccSync = (FRIEND_ASSOCIATE*)_alloca(fsize);
  1919. #else
  1920. FRIEND_ASSOCIATE* pCccSync = (FRIEND_ASSOCIATE*)(new char[fsize]);
  1921. #endif
  1922. pCccSync->ProtocolFamily = pf_friend;
  1923. pCccSync->ProtocolID = friend_c2s_associate;
  1924. pCccSync->bidir = 0;
  1925. char* pBuf = (char*)(pCccSync + 1);
  1926. strcpy(pBuf, ENEMY_UNITNAME);
  1927. pBuf += nG;
  1928. strcpy(pBuf, szPlayer);
  1929. pBuf += nP;
  1930. strcpy(pBuf, szEnemy);
  1931. pBuf += nE;
  1932. g_NewProtocolProcess.PushMsgInTong(pCccSync, fsize);
  1933. #ifndef WIN32
  1934. if (pCccSync)
  1935. delete ((char*)pCccSync);
  1936. #endif
  1937. }
  1938. #endif
  1939. #ifndef _SERVER
  1940. //---------------------------------------------------------------------------
  1941. // 功能:发送可选择聊天频道列表给界面
  1942. //---------------------------------------------------------------------------
  1943. int KPlayerChat::SendSelectChannelList(KUiChatChannel *pList, int nCount)
  1944. {
  1945. // 根据玩家不同的身份作不同的处理 not end
  1946. int i, nTempCount = 0;
  1947. // 目前开放大部分功能
  1948. if (!pList || nCount <= 0)
  1949. {
  1950. for (i = CHAT_CUR_CHANNEL_NONE + 1; i < CHAT_CUR_CHANNEL_NUM; i++)
  1951. {
  1952. switch (i)
  1953. {
  1954. case CHAT_CUR_CHANNEL_ALL:
  1955. // 一般人不能使用这个频道
  1956. // nTempCount++;
  1957. break;
  1958. case CHAT_CUR_CHANNEL_SCREEN:
  1959. // 这个频道始终开放
  1960. nTempCount++;
  1961. break;
  1962. case CHAT_CUR_CHANNEL_SINGLE:
  1963. // QQ聊天使用,不用于选择
  1964. break;
  1965. case CHAT_CUR_CHANNEL_TEAM:
  1966. // 组对才可以选
  1967. if (Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag)
  1968. nTempCount++;
  1969. break;
  1970. case CHAT_CUR_CHANNEL_FACTION:
  1971. // 一般人不能使用这个频道
  1972. nTempCount++;
  1973. break;
  1974. case CHAT_CUR_CHANNEL_TONG:
  1975. // 帮派目前还没有
  1976. break;
  1977. case CHAT_CUR_CHANNEL_SCREENSINGLE:
  1978. // 这个频道不是用来选择的,通过别的操作自动选定
  1979. break;
  1980. case CHAT_CUR_CHANNEL_SYSTEM:
  1981. // 服务器使用,客户端不提供
  1982. break;
  1983. default:
  1984. break;
  1985. }
  1986. }
  1987. return nTempCount;
  1988. }
  1989. for (i = CHAT_CUR_CHANNEL_NONE + 1; i < CHAT_CUR_CHANNEL_NUM; i++)
  1990. {
  1991. if (nTempCount >= nCount)
  1992. break;
  1993. switch (i)
  1994. {
  1995. case CHAT_CUR_CHANNEL_ALL:
  1996. // 一般人不能使用这个频道
  1997. /*
  1998. pList[nTempCount].nChannelNo = CHAT_CUR_CHANNEL_ALL;
  1999. pList[nTempCount].uChannelId = 0;
  2000. pList[nTempCount].nChannelIndex = 0;
  2001. memset(pList[nTempCount].cTitle, 0, sizeof(pList[nTempCount].cTitle));
  2002. strcpy(pList[nTempCount].cTitle, CHAT_CHANNEL_NAME_ALL);
  2003. nTempCount++;
  2004. */
  2005. break;
  2006. case CHAT_CUR_CHANNEL_SCREEN:
  2007. // 这个频道始终开放
  2008. pList[nTempCount].nChannelNo = CHAT_CUR_CHANNEL_SCREEN;
  2009. pList[nTempCount].uChannelId = 0;
  2010. pList[nTempCount].nChannelIndex = 0;
  2011. memset(pList[nTempCount].cTitle, 0, sizeof(pList[nTempCount].cTitle));
  2012. strcpy(pList[nTempCount].cTitle, CHAT_CHANNEL_NAME_SCREEN);
  2013. nTempCount++;
  2014. break;
  2015. case CHAT_CUR_CHANNEL_SINGLE:
  2016. // QQ聊天使用,不用于选择
  2017. break;
  2018. case CHAT_CUR_CHANNEL_TEAM:
  2019. // 组队才可以选
  2020. if (Player[CLIENT_PLAYER_INDEX].m_cTeam.m_nFlag)
  2021. {
  2022. pList[nTempCount].nChannelNo = CHAT_CUR_CHANNEL_TEAM;
  2023. pList[nTempCount].uChannelId = 0;
  2024. pList[nTempCount].nChannelIndex = 0;
  2025. memset(pList[nTempCount].cTitle, 0, sizeof(pList[nTempCount].cTitle));
  2026. strcpy(pList[nTempCount].cTitle, CHAT_CHANNEL_NAME_TEAM);
  2027. nTempCount++;
  2028. }
  2029. break;
  2030. case CHAT_CUR_CHANNEL_FACTION:
  2031. // 一般人不能使用这个频道
  2032. if (Player[CLIENT_PLAYER_INDEX].m_cFaction.GetCurFactionNo() >= 0)
  2033. {
  2034. pList[nTempCount].nChannelNo = CHAT_CUR_CHANNEL_FACTION;
  2035. pList[nTempCount].uChannelId = 0;
  2036. pList[nTempCount].nChannelIndex = 0;
  2037. memset(pList[nTempCount].cTitle, 0, sizeof(pList[nTempCount].cTitle));
  2038. strcpy(pList[nTempCount].cTitle, CHAT_CHANNEL_NAME_FACTION);
  2039. nTempCount++;
  2040. }
  2041. break;
  2042. case CHAT_CUR_CHANNEL_TONG:
  2043. // 帮派目前还没有
  2044. break;
  2045. case CHAT_CUR_CHANNEL_SCREENSINGLE:
  2046. // 这个频道不是用来选择的,通过别的操作自动选定
  2047. break;
  2048. case CHAT_CUR_CHANNEL_SYSTEM:
  2049. // 服务器使用,客户端不提供
  2050. break;
  2051. default:
  2052. break;
  2053. }
  2054. }
  2055. if (nTempCount < nCount)
  2056. memset(&pList[nTempCount], 0, sizeof(KUiChatChannel) * (nCount - nTempCount));
  2057. return nTempCount;
  2058. }
  2059. #endif
  2060. #ifndef _SERVER
  2061. //---------------------------------------------------------------------------
  2062. // 功能:发送可订阅聊天频道列表给界面
  2063. //---------------------------------------------------------------------------
  2064. int KPlayerChat::SendTakeChannelList(KUiChatChannel *pList, int nCount)
  2065. {
  2066. // 根据玩家身份的不同作不同的处理 not end
  2067. int i, nTempCount = 0;
  2068. // 目前开放大部分功能
  2069. if (!pList || nCount <= 0)
  2070. {
  2071. for (i = CHAT_CUR_CHANNEL_NONE + 1; i < CHAT_CUR_CHANNEL_NUM; i++)
  2072. {
  2073. switch (i)
  2074. {
  2075. case CHAT_CUR_CHANNEL_ALL:
  2076. // 这个频道默认订阅,不能取消
  2077. break;
  2078. case CHAT_CUR_CHANNEL_SCREEN:
  2079. // 这个频道默认订阅,不能取消
  2080. break;
  2081. case CHAT_CUR_CHANNEL_SINGLE:
  2082. // QQ聊天使用,默认订阅,不能取消
  2083. break;
  2084. case CHAT_CUR_CHANNEL_TEAM:
  2085. // 这个频道如果订阅了,只有在组队情况下才起作用
  2086. nTempCount++;
  2087. break;
  2088. case CHAT_CUR_CHANNEL_FACTION:
  2089. // 这个频道如果订阅了,只有在门派中才起作用
  2090. nTempCount++;
  2091. break;
  2092. case CHAT_CUR_CHANNEL_TONG:
  2093. // 帮派目前还没有
  2094. break;
  2095. case CHAT_CUR_CHANNEL_SCREENSINGLE:
  2096. // 这个频道如果不订阅,别人就无法直接在屏幕内联系你
  2097. nTempCount++;
  2098. break;
  2099. case CHAT_CUR_CHANNEL_SYSTEM:
  2100. // 服务器使用,默认订阅,不能取消
  2101. break;
  2102. default:
  2103. break;
  2104. }
  2105. }
  2106. return nTempCount;
  2107. }
  2108. for (i = CHAT_CUR_CHANNEL_NONE + 1; i < CHAT_CUR_CHANNEL_NUM; i++)
  2109. {
  2110. if (nTempCount >= nCount)
  2111. break;
  2112. switch (i)
  2113. {
  2114. case CHAT_CUR_CHANNEL_ALL:
  2115. // 这个频道默认订阅,不能取消
  2116. break;
  2117. case CHAT_CUR_CHANNEL_SCREEN:
  2118. // 这个频道默认订阅,不能取消
  2119. break;
  2120. case CHAT_CUR_CHANNEL_SINGLE:
  2121. // QQ聊天使用,默认订阅,不能取消
  2122. break;
  2123. case CHAT_CUR_CHANNEL_TEAM:
  2124. pList[nTempCount].nChannelNo = i;
  2125. pList[nTempCount].uChannelId = 0;
  2126. pList[nTempCount].nChannelIndex = this->CheckTakeChannel(i);
  2127. memset(pList[nTempCount].cTitle, 0, sizeof(pList[nTempCount].cTitle));
  2128. strcpy(pList[nTempCount].cTitle, CHAT_TAKE_CHANNEL_NAME_TEAM);
  2129. nTempCount++;
  2130. break;
  2131. case CHAT_CUR_CHANNEL_FACTION:
  2132. pList[nTempCount].nChannelNo = i;
  2133. pList[nTempCount].uChannelId = 0;
  2134. pList[nTempCount].nChannelIndex = this->CheckTakeChannel(i);
  2135. memset(pList[nTempCount].cTitle, 0, sizeof(pList[nTempCount].cTitle));
  2136. strcpy(pList[nTempCount].cTitle, CHAT_TAKE_CHANNEL_NAME_FACTION);
  2137. nTempCount++;
  2138. break;
  2139. case CHAT_CUR_CHANNEL_TONG:
  2140. // 帮派目前还没有
  2141. break;
  2142. case CHAT_CUR_CHANNEL_SCREENSINGLE:
  2143. pList[nTempCount].nChannelNo = i;
  2144. pList[nTempCount].uChannelId = 0;
  2145. pList[nTempCount].nChannelIndex = this->CheckTakeChannel(i);
  2146. memset(pList[nTempCount].cTitle, 0, sizeof(pList[nTempCount].cTitle));
  2147. strcpy(pList[nTempCount].cTitle, CHAT_TAKE_CHANNEL_NAME_SCREENSINGLE);
  2148. nTempCount++;
  2149. break;
  2150. case CHAT_CUR_CHANNEL_SYSTEM:
  2151. // 服务器使用,默认订阅,不能取消
  2152. break;
  2153. default:
  2154. break;
  2155. }
  2156. }
  2157. if (nTempCount < nCount)
  2158. memset(&pList[nTempCount], 0, sizeof(KUiChatChannel) * (nCount - nTempCount));
  2159. return nTempCount;
  2160. }
  2161. #endif
  2162. #ifndef _SERVER
  2163. //---------------------------------------------------------------------------
  2164. // 功能:获得当前使用聊天频道信息
  2165. //---------------------------------------------------------------------------
  2166. int KPlayerChat::GetCurChannel(KUiChatChannel *pList)
  2167. {
  2168. if (!pList)
  2169. return FALSE;
  2170. pList->nChannelNo = this->m_nCurChannel;
  2171. pList->uChannelId = this->m_dwTargetID;
  2172. pList->nChannelIndex = this->m_nTargetIdx;
  2173. switch (m_nCurChannel)
  2174. {
  2175. case CHAT_CUR_CHANNEL_ALL:
  2176. strcpy(pList->cTitle, CHAT_CHANNEL_NAME_ALL);
  2177. break;
  2178. case CHAT_CUR_CHANNEL_SCREEN:
  2179. strcpy(pList->cTitle, CHAT_CHANNEL_NAME_SCREEN);
  2180. break;
  2181. case CHAT_CUR_CHANNEL_SINGLE:
  2182. strcpy(pList->cTitle, CHAT_CHANNEL_NAME_SINGLE);
  2183. break;
  2184. case CHAT_CUR_CHANNEL_TEAM:
  2185. strcpy(pList->cTitle, CHAT_CHANNEL_NAME_TEAM);
  2186. break;
  2187. case CHAT_CUR_CHANNEL_FACTION:
  2188. strcpy(pList->cTitle, CHAT_CHANNEL_NAME_FACTION);
  2189. break;
  2190. case CHAT_CUR_CHANNEL_TONG:
  2191. strcpy(pList->cTitle, CHAT_CHANNEL_NAME_TONG);
  2192. break;
  2193. case CHAT_CUR_CHANNEL_SCREENSINGLE:
  2194. {
  2195. int nIdx;
  2196. nIdx = NpcSet.SearchID(this->m_dwTargetID);
  2197. if (nIdx > 0)
  2198. {
  2199. strcpy(pList->cTitle, Npc[nIdx].Name);
  2200. }
  2201. else
  2202. {
  2203. strcpy(pList->cTitle, CHAT_CHANNEL_NAME_SCREENSINGLE);
  2204. }
  2205. }
  2206. break;
  2207. case CHAT_CUR_CHANNEL_SYSTEM:
  2208. strcpy(pList->cTitle, CHAT_CHANNEL_NAME_SYSTEM);
  2209. break;
  2210. }
  2211. return TRUE;
  2212. }
  2213. #endif
  2214. #ifndef _SERVER
  2215. //---------------------------------------------------------------------------
  2216. // 功能:获得某个分组信息,返回下一个有效组编号(如果是最后一个有效组,返回-1)
  2217. //---------------------------------------------------------------------------
  2218. int KPlayerChat::IGetTeamInfo(int nTeamNo, KUiChatGroupInfo *psTeamInfo)
  2219. {
  2220. if (nTeamNo < 0 || nTeamNo >= MAX_FRIEND_TEAM || !psTeamInfo)
  2221. return -1;
  2222. for (int i = nTeamNo; i < MAX_FRIEND_TEAM; i++)
  2223. {
  2224. if (m_cFriendTeam[i].m_szTeamName[0])
  2225. {
  2226. strcpy(psTeamInfo->szTitle, this->m_cFriendTeam[i].m_szTeamName);
  2227. psTeamInfo->nNumFriend = this->m_cFriendTeam[i].m_nFriendNo;
  2228. return i;
  2229. }
  2230. }
  2231. return -1;
  2232. }
  2233. #endif
  2234. #ifndef _SERVER
  2235. //---------------------------------------------------------------------------
  2236. // 功能:获得某个分组的所有成员的信息
  2237. //---------------------------------------------------------------------------
  2238. int KPlayerChat::IGetTeamFriendInfo(int nTeamNo, KUiPlayerItem *pList)
  2239. {
  2240. if (nTeamNo < 0 || nTeamNo >= MAX_FRIEND_TEAM || !pList)
  2241. return 0;
  2242. if (!m_cFriendTeam[nTeamNo].m_szTeamName[0] || m_cFriendTeam[nTeamNo].m_nFriendNo <= 0)
  2243. return 0;
  2244. int nRet = 0;
  2245. CChatFriend *pNode = NULL;
  2246. pNode = (CChatFriend*)m_cFriendTeam[nTeamNo].m_cEveryOne.GetHead();
  2247. while (pNode)
  2248. {
  2249. strcpy(pList[nRet].Name, pNode->m_szName);
  2250. if (pNode->m_nPlayerIdx)
  2251. pList[nRet].nData = CHAT_S_ONLINE;
  2252. else
  2253. pList[nRet].nData = CHAT_S_DISCONNECT;
  2254. pList[nRet].nIndex = pNode->m_nPlayerIdx;
  2255. pList[nRet].uId = pNode->m_dwID;
  2256. pNode = (CChatFriend*)pNode->GetNext();
  2257. nRet++;
  2258. }
  2259. return nRet;
  2260. }
  2261. #endif
  2262. //---------------------------------------------------------------------------
  2263. // 功能:构造函数
  2264. //---------------------------------------------------------------------------
  2265. CChatFriendTeam::CChatFriendTeam()
  2266. {
  2267. m_nFriendNo = 0;
  2268. memset(m_szTeamName, 0, 32);
  2269. }
  2270. //---------------------------------------------------------------------------
  2271. // 功能:清空
  2272. //---------------------------------------------------------------------------
  2273. void CChatFriendTeam::Release()
  2274. {
  2275. m_nFriendNo = 0;
  2276. memset(m_szTeamName, 0, 32);
  2277. CChatFriend *pFriend = NULL;
  2278. pFriend = (CChatFriend*)m_cEveryOne.GetHead();
  2279. while (pFriend)
  2280. {
  2281. m_cEveryOne.RemoveHead();
  2282. delete pFriend;
  2283. pFriend = (CChatFriend*)m_cEveryOne.GetHead();
  2284. }
  2285. }
  2286. #ifdef _SERVER
  2287. //---------------------------------------------------------------------------
  2288. // 功能:玩家登陆的时候从数据库获得数据时专用
  2289. //---------------------------------------------------------------------------
  2290. void CChatFriendTeam::DataBaseAddOne(int nSelfIdx, DWORD dwID, char *lpszName)
  2291. {
  2292. if (!lpszName || !lpszName[0])
  2293. return;
  2294. // 判断好友是否在线
  2295. CChatFriend *pFriend = NULL;
  2296. pFriend = new CChatFriend;
  2297. if ( !pFriend )
  2298. return;
  2299. pFriend->m_dwID = dwID;
  2300. pFriend->m_nPlayerIdx = PlayerSet.FindSame(dwID);
  2301. g_StrCpy(pFriend->m_szName, lpszName);
  2302. m_cEveryOne.AddTail(pFriend);
  2303. m_nFriendNo++;
  2304. // 通知好友自己上线了
  2305. if (pFriend->m_nPlayerIdx > 0)
  2306. Player[pFriend->m_nPlayerIdx].ChatFriendOnLine(Player[nSelfIdx].m_dwID, nSelfIdx);
  2307. }
  2308. #endif
  2309. #ifndef _SERVER
  2310. void KCHAT_RECORDER::SetTime()
  2311. {
  2312. SYSTEMTIME sTime;
  2313. GetLocalTime(&sTime);
  2314. sprintf(m_szDay, "%04d.%02d.%02d", sTime.wYear, sTime.wMonth, sTime.wDay);
  2315. sprintf(m_szTime, "%02d:%02d:%02d", sTime.wHour, sTime.wMinute, sTime.wSecond);
  2316. }
  2317. void KCHAT_RECORDER::SaveSentenceSingle(char *lpszSelfName, char *lpszTarget, char *lpszTalkerName, char *lpszSentence)
  2318. {
  2319. // 暂时关闭
  2320. return;
  2321. if (!lpszSelfName || !lpszTarget || !lpszTalkerName || !lpszSentence)
  2322. return;
  2323. if (!lpszSelfName[0] || !lpszTarget[0] || !lpszTalkerName[0] || !lpszSentence[0])
  2324. return;
  2325. // 产生出相应路径
  2326. char szPath[MAX_PATH], szBuf[MAX_PATH], szName[MAX_PATH];
  2327. g_StrCpy(szPath, CHAT_PATH);
  2328. g_StrCat(szPath, "\");
  2329. g_StrCat(szPath, lpszSelfName);
  2330. g_CreatePath(szPath);
  2331. // g_SetFilePath(szPath);
  2332. SetTime();
  2333. KFile cFile;
  2334. sprintf(szName, "%s.rcd", lpszTarget);
  2335. g_UnitePathAndName(szPath, szName, szBuf);
  2336. if ( !cFile.Append(szBuf) )
  2337. return;
  2338. cFile.Write(m_szDay, sizeof(m_szDay) - 1);
  2339. cFile.Write("  ", 2);
  2340. cFile.Write(this->m_szTime, sizeof(m_szTime) - 1);
  2341. cFile.Write("  ", 2);
  2342. cFile.Write(lpszTalkerName, strlen(lpszTalkerName));
  2343. cFile.Write("rn", 1);
  2344. if (strlen(lpszSentence) < MAX_SENTENCE_LENGTH)
  2345. cFile.Write(lpszSentence, strlen(lpszSentence));
  2346. else
  2347. cFile.Write(lpszSentence, MAX_SENTENCE_LENGTH - 1);
  2348. cFile.Write("rn", 1);
  2349. cFile.Close();
  2350. }
  2351. void KCHAT_RECORDER::SaveSentenceChannel(char *lpszSelfName, char *lpszTalkerName, char *lpszSentence)
  2352. {
  2353. // 暂时关闭
  2354. return;
  2355. if (!lpszSelfName || !lpszTalkerName || !lpszSentence)
  2356. return;
  2357. if (!lpszSelfName[0] || !lpszTalkerName[0] || !lpszSentence[0])
  2358. return;
  2359. SetTime();
  2360. m_szDay[4] = '_';
  2361. m_szDay[7] = '_';
  2362. // 产生出相应路径
  2363. char szPath[MAX_PATH], szName[MAX_PATH], szBuf[MAX_PATH];
  2364. g_StrCpy(szPath, CHAT_PATH);
  2365. g_StrCat(szPath, "\");
  2366. g_StrCat(szPath, lpszSelfName);
  2367. g_StrCat(szPath, "\");
  2368. g_StrCat(szPath, m_szDay);
  2369. g_CreatePath(szPath);
  2370. // g_SetFilePath(szPath);
  2371. sprintf(szName, "%s.rcd", m_szDay);
  2372. g_UnitePathAndName(szPath, szName, szBuf);
  2373. KFile cFile;
  2374. if ( !cFile.Append(szBuf) )
  2375. return;
  2376. cFile.Write(m_szTime, sizeof(m_szTime) - 1);
  2377. cFile.Write("  ", 2);
  2378. cFile.Write(lpszTalkerName, strlen(lpszTalkerName));
  2379. cFile.Write("rn", 1);
  2380. if (strlen(lpszSentence) < MAX_SENTENCE_LENGTH)
  2381. cFile.Write(lpszSentence, strlen(lpszSentence));
  2382. else
  2383. cFile.Write(lpszSentence, MAX_SENTENCE_LENGTH - 1);
  2384. cFile.Write("rn", 1);
  2385. cFile.Close();
  2386. }
  2387. #endif