void CPlayer::SetNick ( const char* szNick ) { if ( !m_strNick.empty () && m_strNick != szNick ) { // If changing, add the new name to the whowas list g_pGame->GetConsole ()->GetWhoWas ()->Add ( szNick, inet_addr ( GetSourceIP() ), GetSerial (), GetPlayerVersion (), GetAccount ()->GetName () ); } m_strNick.AssignLeft ( szNick, MAX_NICK_LENGTH ); }
void MainWindow::onReceivedPacket(EthernetPacket *packetData) { QString packetLengthColumn; mUI->infoTable->insertRow(mReceivedPackets); mUI->infoTable->setItem(mReceivedPackets, 0, new QTableWidgetItem((packetData->GetType().c_str()))); mUI->infoTable->setItem(mReceivedPackets, 1, new QTableWidgetItem((packetData->GetSourceMAC()).c_str())); mUI->infoTable->setItem(mReceivedPackets, 2, new QTableWidgetItem((packetData->GetDestinationMAC()).c_str())); auto packetType = packetData->GetType(); if (packetType == "IP" || packetType == "TCP" || packetType == "UDP") { auto ipPacket = reinterpret_cast<IPPacket*>(packetData); mUI->infoTable->setItem(mReceivedPackets, 3, new QTableWidgetItem((ipPacket->GetSourceIP()).c_str())); mUI->infoTable->setItem(mReceivedPackets, 4, new QTableWidgetItem((ipPacket->GetDestinationIP()).c_str())); if (packetType == "TCP") { auto tcpPacket = reinterpret_cast<TcpPacket*>(packetData); mUI->infoTable->setHorizontalHeaderItem(5, new QTableWidgetItem("Src. Port")); mUI->infoTable->setHorizontalHeaderItem(6, new QTableWidgetItem("Dst. Port")); mUI->infoTable->item(mReceivedPackets, 0)->setBackground(Qt::yellow); mUI->infoTable->setItem(mReceivedPackets, 5, new QTableWidgetItem(std::to_string((tcpPacket->GetSourcePort())).c_str())); mUI->infoTable->setItem(mReceivedPackets, 6, new QTableWidgetItem(std::to_string((tcpPacket->GetDestinationPort())).c_str())); } else if (packetType == "UDP") { auto udpPacket = reinterpret_cast<UDPPacket*>(packetData); mUI->infoTable->setHorizontalHeaderItem(5, new QTableWidgetItem("Src. Port")); mUI->infoTable->setHorizontalHeaderItem(6, new QTableWidgetItem("Dst. Port")); mUI->infoTable->item(mReceivedPackets, 0)->setBackground(Qt::blue); mUI->infoTable->setItem(mReceivedPackets, 5, new QTableWidgetItem(std::to_string((udpPacket->GetSourcePort())).c_str())); mUI->infoTable->setItem(mReceivedPackets, 6, new QTableWidgetItem(std::to_string((udpPacket->GetDestinationPort())).c_str())); } else { mUI->infoTable->item(mReceivedPackets, 0)->setBackground(QColor(0, 100,100)); } } // Network Protocol is other type else { } mReceivedPackets++; mPacketDataBuffer->push_back(packetData); }
void CPlayer::SetNick ( const char* szNick ) { if ( strlen ( m_szNick ) > 0 && strcmp ( m_szNick, szNick ) != 0 ) { // If changing, add the new name to the whowas list char szIP [22]; g_pGame->GetConsole ()->GetWhoWas ()->Add ( szNick, inet_addr ( GetSourceIP( szIP ) ), GetSerial (), GetPlayerVersion () ); } assert ( sizeof ( m_szNick ) == MAX_NICK_LENGTH + 1 ); // Copy the nick to us STRNCPY ( m_szNick, szNick, MAX_NICK_LENGTH + 1 ); }