void CFriendList::AddFriend(const CMD4Hash& userhash, uint32 lastUsedIP, uint32 lastUsedPort, const wxString& name, uint32 lastSeen, uint32 lastChatted) { CFriend* NewFriend = new CFriend( userhash, lastSeen, lastUsedIP, lastUsedPort, lastChatted, name); AddFriend( NewFriend ); }
void CPlayerFriend::OnOtherReplayMeAboutAddItbeFriend(bool bAgree,CPlayerFriend* pWhoReplyMe) { stMsgPlayerAddFriendRet msg ; msg.nRet = 0 ; msg.nTaregtUID = pWhoReplyMe->GetPlayer()->GetUserUID() ; memset(msg.pReplayerName,0,sizeof(msg.pReplayerName)); sprintf_s(msg.pReplayerName,sizeof(msg.pReplayerName),"%s",pWhoReplyMe->GetPlayer()->GetBaseData()->GetPlayerName()) ; if ( bAgree == false ) { msg.nRet = 1 ; } else { if ( IsFriendListFull() ) { msg.nRet = 2 ; } else { AddFriend(msg.nTaregtUID) ; } } SendMsg(&msg,sizeof(msg)) ; LOGFMTD("uid = %d send msg stMsgPlayerAddFriendRet",GetPlayer()->GetUserUID()); }
void CFriendList::AddFriend(const CClientRef& toadd) { if ( toadd.IsFriend() ) { return; } CFriend* NewFriend = new CFriend( toadd ); toadd.SetFriend(NewFriend); AddFriend(NewFriend, false); // has already notified }
void LocalRAUser::OnFriendListCB( RequestObject* pObj ) { if( pObj->m_bResponse ) { if( strncmp( pObj->m_sResponse, "OK:", 3 ) == 0 ) { if( pObj->m_sResponse[3] != '\0' ) { char* cpIter = &(pObj->m_sResponse[3]); unsigned int nCharsRead = 0; do { char* pUser = _ReadStringTil( '&', cpIter, TRUE ); char* pPoints = _ReadStringTil( '&', cpIter, TRUE ); char* pActivity = _ReadStringTil( '\n', cpIter, TRUE ); unsigned int nScore = strtol( pPoints, NULL, 10 ); if( !pActivity || strlen( pActivity ) < 2 || strcmp( pActivity, "_" ) == 0 ) pActivity = "Unknown!"; if( pUser && pPoints && pActivity ) { RAUser& NewFriend = AddFriend( pUser, nScore ); //TBD NewFriend.UpdateActivity( pActivity ); //TBD } } while ( (*cpIter) != '\0' ); } } else { // Issues?! //assert(0); } } }
//--------------------------------- //------------METODI---------------- //---------------------------------- void LinQedInClientView::initView() { //allocamento dei campi dati nello heap tabWidget = new QTabWidget(this); thisLayout = new QVBoxLayout(); //config tabWidget tabWidget->addTab(BaseInfTab,"Informazioni"); tabWidget->addTab(NetworkTab,"Amici"); tabWidget->addTab(SearchTab,"Cerca"); //config thisLayout thisLayout->addWidget(tabWidget); //config this this->setWindowTitle(tr("LinQedInClient")); this->setLayout(thisLayout); this->setMinimumSize(850,650); //CONNECT //config TAB BaseInformation connect(BaseInfTab,SIGNAL(SaveBtnClicked(UserBaseInformations*)),this,SIGNAL(BaseInfChanged(UserBaseInformations*))); connect(BaseInfTab,SIGNAL(BaseInfAsked()),this,SIGNAL(BaseInfAsked())); //config TAB Network connect(NetworkTab,SIGNAL(RemoveFriendClicked(QString)),this,SIGNAL(FriendRemoved(QString))); connect(NetworkTab,SIGNAL(FriendsNetworkAsked()),this,SIGNAL(FriendsNetworkAsked())); //config SearchTab connect(SearchTab,SIGNAL(UserFormAsked()),this,SIGNAL(UserFormAsked())); connect(SearchTab,SIGNAL(Search(UserBaseInformations*)),this,SIGNAL(Search(UserBaseInformations*))); connect(SearchTab,SIGNAL(AddFriend(QString)),this,SIGNAL(FriendAdded(QString))); connect(NetworkTab,SIGNAL(ViewProfile(QString)),this,SIGNAL(ViewProfile(QString))); connect(SearchTab,SIGNAL(ViewProfile(QString)),this,SIGNAL(ViewProfile(QString))); }
/********************************************************* 函数名称:RecvMsg 功能描述:接收信息 作者: 余志荣 创建日期:2016-08-03 参数说明:pSocket -- 接收到消息的pSocket 返 回 值:接收到的字节数 *********************************************************/ int CSocketServerDlg::RecvMsg(CChatSocket * pSocket) { int iBufSize = MSG_SIZE_MAX; // 接收的最大字节数 struct MSG_T *msg = new struct MSG_T; int iRes = pSocket->Receive((char *)msg, iBufSize); if(iRes == SOCKET_ERROR) // 接收失败 { //MessageBox(_T("SOCKET_ERROR")); OutputInfo(_T("SOCKET_ERROR")); return 0; } switch(msg->nType) { // 登陆/下线 case LOGIN: // 登录消息 Login((struct MSG_LOGIN *)msg, pSocket); break; case LOGIN_OUT: // 下线消息 LoginOut((struct MSG_LOGIN *)msg, pSocket); break; case GET_FRIEND_LIST: // 请求获得好友列表 GetFriendList((struct MSG_USERINFO *)msg, pSocket);break; case GET_ALL_FRIEND_INFO: // 请求获得全部好友的基本信息 GetAllFriendInfo((struct MSG_FRND_INFO*)msg, pSocket);break; case SET_USER_STATUS: // 设置在线状态 SetUserStatus((struct MSG_USERINFO *)msg, pSocket);break; // 注册 case REGISTER: // 注册消息 Register((struct MSG_REGISTER *)msg, pSocket); break; // 一对一聊天 case GET_FRIEND_INFO: // 请求获得好友信息 GetFriendInfo((struct MSG_USERINFO *)msg, pSocket);break; case CHATING_TEXT_MSG: // 聊天消息 RelayChatMsg((struct MSG_TRANSPOND *)msg, pSocket);break; // 增删好友 case ADD_FRIEND_REQUEST: // 添加好友请求 RelayChatMsg((struct MSG_TRANSPOND *)msg, pSocket);break; case ADD_FRIEND_ANSWER: // 添加请求回应 AddFriend((struct MSG_TRANSPOND *)msg, pSocket);break; case DELETE_FRIEND: // 删除好友 DeleteFriend((MSG_MAKE_FRIEND *)msg, pSocket);break; case GET_STRANGER_INFO: // 请求获得陌生人信息 GetStrangerInfo((struct MSG_USERINFO *)msg, pSocket);break; // 心跳包 case HEARTBEAT: pSocket->Send(msg, sizeof(MSG_SYS)); //TRACE(pSocket->m_userID); //TRACE("\n"); break; // 文件传输 case MESSAGE_FILE_REQUEST: // 发送请求 FileTransRequest((MSG_FILE_REQUEST*)msg); break; case MESSAGE_FILE_AGREE: // 同意发送 case MESSAGE_FILE_REFUSE: // 拒绝发送 case MESSAGE_FILE_ERROR: // 出现错误 FileTransAnswer((MSG_FILE_REQUEST*)msg); break; case FILE_TRANS_SOCKET: strcpy_s(pSocket->m_userID, ((MSG_SYS*)msg)->nID); AddToFileSocketList(pSocket); break; case MESSAGE_FILE_TRANS_BEGIN: case MESSAGE_FILE_TRANS_END: FileTransOpera((MSG_FILE_OPERA *)msg, pSocket); //FileTransRelay((MSG_FILE_REQUEST*)msg);// (未使用) break; case MESSAGE_FILE_CONTENT: FileTransRelay((MSG_FILE_CONTENT*)msg); break; default: //MessageBox(L"未定义的数据类型!"); break; } return iRes; }
bool CPlayerFriend::OnMessage(stMsg* pMsg, eMsgPort eSenderPort ) { switch ( pMsg->usMsgType ) { case MSG_READ_FRIEND_LIST: { stMsgReadFriendListRet* pRet = (stMsgReadFriendListRet*)pMsg ; char* pBuffer = (char*)&pRet; pBuffer += sizeof(stMsgReadFriendListRet); if ( pRet->nFriendCountLen ) { Json::Reader reader ; Json::Value arrayValue ; reader.parse(pBuffer,pBuffer + pRet->nFriendCountLen,arrayValue,false); for ( uint16_t nIdx = 0 ; nIdx < arrayValue.size(); ++nIdx ) { m_vAllFriends.insert(arrayValue[nIdx].asUInt()); } } LOGFMTD("read friend list ok uid = %d",GetPlayer()->GetUserUID()); } break; case MSG_REQUEST_FRIEND_LIST: { SendListToClient(); } break; case MSG_PLAYER_ADD_FRIEND: { stMsgPlayerAddFriend* pMsgRet = (stMsgPlayerAddFriend*)pMsg ; CPlayer* pTargetPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerByUserUID(pMsgRet->nTargetUID,false) ; stMsgPlayerAddFriendRet msg ; msg.nRet = 0 ; msg.nTaregtUID = pMsgRet->nTargetUID ; memset(msg.pReplayerName,0,sizeof(msg.pReplayerName)); if ( pTargetPlayer ) { sprintf_s(msg.pReplayerName,sizeof(msg.pReplayerName),"%s",pTargetPlayer->GetBaseData()->GetPlayerName()) ; } if ( IsFriendListFull() ) { msg.nRet = 2 ; LOGFMTD("friend list is full, can not add"); } else if ( isPlayerUIDFriend(pMsgRet->nTargetUID) ) { msg.nRet = 5 ; LOGFMTD("already your friend , can not add"); } else if ( pTargetPlayer == nullptr ) { msg.nRet = 4 ; } else { CPlayerFriend* pTaretFriendModule = (CPlayerFriend*)pTargetPlayer->GetComponent(ePlayerComponent_Friend); if ( pTaretFriendModule->IsFriendListFull() ) { msg.nRet = 3 ; } else { pTaretFriendModule->OnPlayerWantAddMe(this); } } if ( msg.nRet ) { SendMsg(&msg,sizeof(msg)) ; } } break; case MSG_PLAYER_BE_ADDED_FRIEND_REPLY: { stMsgPlayerBeAddedFriendReply* pMsgRet = (stMsgPlayerBeAddedFriendReply*)pMsg ; CPlayer* pReplyToPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerByUserUID(pMsgRet->nReplayToPlayerUserUID) ; CPlayerFriend* pReplyToFriendComponed = NULL; stMsgPlayerBeAddedFriendReplyRet msgBack ; msgBack.nNewFriendUserUID = pMsgRet->nReplayToPlayerUserUID ; msgBack.nRet = 0 ; if ( pReplyToPlayer ) { pReplyToFriendComponed = (CPlayerFriend*)pReplyToPlayer->GetComponent(ePlayerComponent_Friend) ; } if ( pReplyToFriendComponed ) { if ( IsFriendListFull() ) { msgBack.nRet = 2 ; } if ( msgBack.nRet == 0 && pReplyToFriendComponed->IsFriendListFull() ) { msgBack.nRet = 1 ; } if ( pMsgRet->bAgree && msgBack.nRet == 0 ) { AddFriend(pMsgRet->nReplayToPlayerUserUID) ; } pReplyToFriendComponed->OnOtherReplayMeAboutAddItbeFriend(pMsgRet->bAgree,this); } else { LOGFMTE("%d uid offline can not reply add friend ",pMsgRet->nReplayToPlayerUserUID); msgBack.nRet = 3 ; } if ( pMsgRet->bAgree ) { SendMsg(&msgBack,sizeof(msgBack)) ; LOGFMTD("uid = %u msg type = stMsgPlayerBeAddedFriendReplyRet, typeid = %s",GetPlayer()->GetUserUID(),typeid(stMsgPlayerBeAddedFriendReplyRet)) ; } } break; case MSG_PLAYER_DELETE_FRIEND: { stMsgPlayerDelteFriendRet msgBack ; msgBack.nRet = 0 ; stMsgPlayerDelteFriend* pMsgRet = (stMsgPlayerDelteFriend*)pMsg ; msgBack.nDeleteUID = pMsgRet->nDelteFriendUserUID ; if ( isPlayerUIDFriend(pMsgRet->nDelteFriendUserUID) == false ) { msgBack.nRet = 1 ; } else { RemoveFriendByUID(pMsgRet->nDelteFriendUserUID) ; } SendMsg(&msgBack,sizeof(msgBack)); CPlayer* pReplyToPlayer = CGameServerApp::SharedGameServerApp()->GetPlayerMgr()->GetPlayerByUserUID(msgBack.nDeleteUID) ; CPlayerFriend* pReplyToFriendComponed = NULL; if ( pReplyToPlayer ) { pReplyToFriendComponed = (CPlayerFriend*)pReplyToPlayer->GetComponent(ePlayerComponent_Friend) ; pReplyToFriendComponed->RemoveFriendByUID(GetPlayer()->GetUserUID()) ; } else { LOGFMTE("no online tell mail to delete friend"); } } break; default: return false ; } return true ; }