本文整理汇总了C++中ArNetPacket::setCommand方法的典型用法代码示例。如果您正苦于以下问题:C++ ArNetPacket::setCommand方法的具体用法?C++ ArNetPacket::setCommand怎么用?C++ ArNetPacket::setCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ArNetPacket
的用法示例。
在下文中一共展示了ArNetPacket::setCommand方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: processAuthPacket
AREXPORT void ArServerClient::processAuthPacket(ArNetPacket *packet,
struct sockaddr_in *sin)
{
ArNetPacket retPacket;
long authKey;
// check the auth key again, just in case
authKey = packet->bufToUByte4();
if (authKey != myAuthKey)
{
ArLog::log(ArLog::Terse, "ArServerClient: authKey given does not match actual authKey, horrible error.");
return;
}
if (mySin.sin_port != sin->sin_port)
{
ArLog::log(myVerboseLogLevel,
"Client says it is using port %u but is using port %u\n",
ArSocket::netToHostOrder(mySin.sin_port),
ArSocket::netToHostOrder(sin->sin_port));
}
myUdpConfirmedFrom = true;
mySin.sin_port = sin->sin_port;
mySin.sin_addr = sin->sin_addr;
ArLog::log(myVerboseLogLevel, "Client connected to server on udp port %u",
ArSocket::netToHostOrder(mySin.sin_port));
// TODO put some state info here to note that its fully udp connected
retPacket.empty();
retPacket.setCommand(ArServerCommands::UDP_INTRODUCTION);
retPacket.byte4ToBuf(myIntroKey);
sendPacketUdp(&retPacket);
retPacket.empty();
retPacket.setCommand(ArServerCommands::UDP_CONFIRMATION);
sendPacketTcp(&retPacket);
}
示例2: netPopupList
AREXPORT void ArServerHandlerPopup::netPopupList(ArServerClient *client,
ArNetPacket *packet)
{
ArLog::log(ArLog::Normal, "Sending popup list");
std::map<ArTypes::Byte4, PopupData *>::iterator it;
ArNetPacket sendingPacket;
PopupData *popupData;
myDataMutex.lock();
for (it = myMap.begin(); it != myMap.end(); it++)
{
popupData = (*it).second;
sendingPacket.empty();
ArLog::log(ArLog::Normal, "Sending popup %d", popupData->myID);
buildPacket(&sendingPacket, popupData);
sendingPacket.setCommand(myServer->findCommandFromName("popupCreate"));
client->sendPacketTcp(&sendingPacket);
}
sendingPacket.empty();
client->sendPacketTcp(&sendingPacket);
ArLog::log(ArLog::Normal, "Sent popups");
myDataMutex.unlock();
}
示例3: shutdown
AREXPORT void ArServerClient::shutdown(void)
{
ArNetPacket packet;
packet.setCommand(ArServerCommands::SHUTDOWN);
sendPacketTcp(&packet);
myTcpSender.sendData();
}
示例4: tcpCallback
AREXPORT bool ArServerClient::tcpCallback(void)
{
if (myState == STATE_REJECTED)
{
myTcpSender.sendData();
ArUtil::sleep(10);
return false;
}
if (myState == STATE_DISCONNECTED && (myHaveSlowPackets ||
myHaveIdlePackets))
return true;
if (myState == STATE_DISCONNECTED)
return false;
if (myState == STATE_SENT_INTRO && myStateStart.secSince() >= 60)
{
ArLog::log(myVerboseLogLevel, "%sTook too long for %s to connect",
myLogPrefix.c_str(), getIPString());
return false;
}
if (myTcpOnly && !mySentTcpOnly)
{
mySentTcpOnly = true;
ArNetPacket sending;
sending.setCommand(ArServerCommands::TCP_ONLY);
sendPacketTcp(&sending);
}
if (!myTcpReceiver.readData())
{
ArLog::log(myVerboseLogLevel, "%sTrouble receiving tcp data from %s",
myLogPrefix.c_str(), getIPString());
internalSwitchState(STATE_DISCONNECTED);
return tcpCallback();
//return false;
}
if (!myTcpSender.sendData())
{
ArLog::log(myVerboseLogLevel, "%sTrouble sending tcp data to %s",
myLogPrefix.c_str(), getIPString());
internalSwitchState(STATE_DISCONNECTED);
return tcpCallback();
//return false;
}
return true;
}
示例5: requestOnceUdp
AREXPORT bool ArCentralForwarder::requestOnceUdp(const char *name,
ArNetPacket *packet,
bool quiet)
{
if (myClient != NULL)
{
unsigned int commandNum = myClient->findCommandFromName(name);
if (commandNum == 0)
{
if (!quiet)
ArLog::log(ArLog::Normal,
"ArCentralForwarder::%s::requestOnce: Can't find commandNum for %s",
getRobotName(), name);
return false;
}
//return myClient->requestOnceUdp(name, packet, quiet);
if (packet != NULL)
{
packet->setCommand(commandNum);
packet->finalizePacket();
return internalRequestOnce(NULL, packet, false);
}
else
{
ArNetPacket tempPacket;
tempPacket.setCommand(commandNum);
tempPacket.finalizePacket();
return internalRequestOnce(NULL, &tempPacket, false);
}
}
else
{
if (!quiet)
ArLog::log(ArLog::Normal,
"ArCentralForwarder::%s::requestOnce: Tried to call (for %s) while client was still NULL",
getRobotName(), name);
return false;
}
}
示例6: ArServerClient
AREXPORT ArServerClient::ArServerClient(
ArSocket *tcpSocket, unsigned int udpPort, long authKey,
long introKey, ArRetFunctor2<bool, ArNetPacket *,
struct sockaddr_in *> *sendUdpCallback,
std::map<unsigned int, ArServerData *> *dataMap,
const char *passwordKey, const char *serverKey,
const ArServerUserInfo *userInfo, int rejecting,
const char *rejectingString, bool debugLogging,
const char *serverClientName, bool logPasswordFailureVerbosely,
bool allowSlowPackets, bool allowIdlePackets) :
myProcessPacketCB(this, &ArServerClient::processPacket, NULL, true)
{
ArNetPacket packet;
// set our default to no command
pushCommand(0);
myAuthKey = authKey;
myIntroKey = introKey;
myTcpSocket.transfer(tcpSocket);
myTcpSocket.setCloseCallback(tcpSocket->getCloseCallback());
myTcpSocket.setNonBlock();
myTcpReceiver.setSocket(&myTcpSocket);
myTcpReceiver.setProcessPacketCB(&myProcessPacketCB);
myTcpSender.setSocket(&myTcpSocket);
mySendUdpCB = sendUdpCallback;
myDataMap = dataMap;
if (udpPort == 0)
myTcpOnly = true;
else
myTcpOnly = false;
mySentTcpOnly = myTcpOnly;
myUserInfo = userInfo;
myPasswordKey = passwordKey;
myServerKey = serverKey;
myRejecting = rejecting;
if (rejectingString != NULL)
myRejectingString = rejectingString;
myDebugLogging = debugLogging;
if (myDebugLogging)
myVerboseLogLevel = ArLog::Normal;
else
myVerboseLogLevel = ArLog::Verbose;
myTcpSender.setDebugLogging(myDebugLogging);
myLogPrefix = serverClientName;
myLogPrefix += ": ";
myTcpSender.setLoggingPrefix(myLogPrefix.c_str());
myTcpReceiver.setLoggingPrefix(myLogPrefix.c_str());
myLogPasswordFailureVerbosely = logPasswordFailureVerbosely;
mySlowPacketsMutex.setLogName("ArServerClient::mySlowPacketsMutex");
myIdlePacketsMutex.setLogName("ArServerClient::myIdlePacketsMutex");
myAllowSlowPackets = allowSlowPackets;
myAllowIdlePackets = allowIdlePackets;
setIdentifier(ArServerClientIdentifier());
internalSwitchState(STATE_SENT_INTRO);
packet.empty();
packet.setCommand(ArServerCommands::INTRODUCTION);
packet.strToBuf("alpha");
packet.uByte2ToBuf(udpPort);
packet.uByte4ToBuf(myAuthKey);
packet.uByte4ToBuf(myIntroKey);
packet.strToBuf(myPasswordKey.c_str());
sendPacketTcp(&packet);
mySlowIdleThread = NULL;
myHaveSlowPackets = false;
myHaveIdlePackets = false;
myCreationTime.setToNow();
resetTracking();
}
示例7: processPacket
AREXPORT void ArServerClient::processPacket(ArNetPacket *packet, bool tcp)
{
std::string str;
struct sockaddr_in sin;
unsigned int clientUdpPort;
ArNetPacket retPacket;
//printf("Command number %d\n", packet->getCommand());
// if we're in intro mode and received back the intro
if (myState == STATE_SENT_INTRO &&
packet->getCommand() == ArClientCommands::INTRODUCTION)
{
char user[512];
unsigned char password[16];
clientUdpPort = packet->bufToUByte2();
packet->bufToStr(user, sizeof(user));
packet->bufToData((char *)password, 16);
if (myRejecting != 0)
{
retPacket.empty();
retPacket.setCommand(ArServerCommands::REJECTED);
retPacket.byte2ToBuf(myRejecting);
retPacket.strToBuf(myRejectingString.c_str());
sendPacketTcp(&retPacket);
if (myRejecting == 2)
ArLog::log(ArLog::Normal,
"%sRejected connection from %s since we're using a central server at %s",
myLogPrefix.c_str(), getIPString(),
myRejectingString.c_str());
internalSwitchState(STATE_REJECTED);
return;
}
// if user info is NULL we're not checking passwords
if (myUserInfo != NULL &&
!myUserInfo->matchUserPassword(user, password, myPasswordKey.c_str(),
myServerKey.c_str(),
myLogPasswordFailureVerbosely))
{
retPacket.empty();
retPacket.setCommand(ArServerCommands::REJECTED);
retPacket.byte2ToBuf(1);
retPacket.strToBuf("");
sendPacketTcp(&retPacket);
ArLog::log(ArLog::Normal, "%sRejected user '%s' or password from %s",
myLogPrefix.c_str(), user, getIPString());
internalSwitchState(STATE_REJECTED);
return;
}
if (myUserInfo != NULL)
myGroups = myUserInfo->getUsersGroups(user);
else
myGroups.clear();
sin.sin_family = AF_INET;
sin.sin_addr = *myTcpSocket.inAddr();
sin.sin_port = ArSocket::hostToNetOrder(clientUdpPort);
if (myUserInfo != NULL)
ArLog::log(ArLog::Normal,
"%sClient connected from %s with user %s",
myLogPrefix.c_str(), getIPString(), user);
else
ArLog::log(ArLog::Normal,
"%sClient connected from %s", myLogPrefix.c_str(),
getIPString());
setUdpAddress(&sin);
// send that we've connected
retPacket.empty();
retPacket.setCommand(ArServerCommands::CONNECTED);
sendPacketTcp(&retPacket);
// note that we're connected
internalSwitchState(STATE_CONNECTED);
// send them the list
sendListPacket();
// send the udp introduction if we're using udp
if (!myTcpOnly)
{
retPacket.empty();
retPacket.setCommand(ArServerCommands::UDP_INTRODUCTION);
retPacket.byte4ToBuf(myIntroKey);
sendPacketUdp(&retPacket);
}
}
// if we aren't in intro mode and got an intro somethings wrong
else if (packet->getCommand() == ArClientCommands::INTRODUCTION)
{
ArLog::log(ArLog::Terse,
"%sReceived introduction when not in intro mode",
myLogPrefix.c_str());
return;
}
// if we got this over tcp then they only want tcp
else if (packet->getCommand() == ArClientCommands::UDP_INTRODUCTION)
{
if (!myTcpOnly)
{
ArLog::log(ArLog::Normal, "%sGot UDP introduction over tcp, assuming client only wants tcp data.", myLogPrefix.c_str());
myTcpOnly = true;
//.........这里部分代码省略.........
示例8: sendListPacket
void ArServerClient::sendListPacket(void)
{
ArNetPacket packet;
std::map<unsigned int, ArServerData *>::iterator it;
unsigned int count;
unsigned int shortLen;
unsigned int longLen;
ArServerData *serverData;
// First we send a list of numbers, names and descriptions
packet.setCommand(ArServerCommands::LIST);
// number of entries (we'll overwrite it later with the right number)
shortLen = packet.getLength();
packet.uByte2ToBuf(0);
// loop through the data to build the packet
for (it = myDataMap->begin(), count = 0; it != myDataMap->end(); it++)
{
serverData = (*it).second;
if (myUserInfo == NULL ||
serverData->getCommandGroup() == NULL ||
serverData->getCommandGroup()[0] == '\0' ||
myGroups.count(serverData->getCommandGroup()) != 0 ||
myGroups.count("all") != 0)
{
count++;
packet.uByte2ToBuf(serverData->getCommand());
packet.strToBuf(serverData->getName());
packet.strToBuf(serverData->getDescription());
}
}
// put the real number of entries in the right spot
longLen = packet.getLength();
packet.setLength(shortLen);
packet.uByte2ToBuf(count);
packet.setLength(longLen);
sendPacketTcp(&packet);
// then we send a list of the arguments and returns... they aren't
// combined so that the packet structure doesn't need to change
packet.empty();
packet.setCommand(ArServerCommands::LISTARGRET);
// number of entries (we'll overwrite it later with the right number)
shortLen = packet.getLength();
packet.uByte2ToBuf(0);
// loop through the data to build the packet
for (it = myDataMap->begin(), count = 0; it != myDataMap->end(); it++)
{
serverData = (*it).second;
if (myUserInfo == NULL ||
serverData->getCommandGroup() == NULL ||
serverData->getCommandGroup()[0] == '\0' ||
myGroups.count(serverData->getCommandGroup()) != 0 ||
myGroups.count("all") != 0)
{
count++;
packet.uByte2ToBuf(serverData->getCommand());
packet.strToBuf(serverData->getArgumentDescription());
packet.strToBuf(serverData->getReturnDescription());
}
}
// put the real number of entries in the right spot
longLen = packet.getLength();
packet.setLength(shortLen);
packet.uByte2ToBuf(count);
packet.setLength(longLen);
sendPacketTcp(&packet);
// then we send a list of command groups... they aren't
// combined so that the packet structure doesn't need to change
packet.empty();
packet.setCommand(ArServerCommands::LISTGROUPANDFLAGS);
// number of entries (we'll overwrite it later with the right number)
shortLen = packet.getLength();
packet.uByte2ToBuf(0);
// loop through the data to build the packet
for (it = myDataMap->begin(), count = 0; it != myDataMap->end(); it++)
{
serverData = (*it).second;
if (myUserInfo == NULL ||
serverData->getCommandGroup() == NULL ||
serverData->getCommandGroup()[0] == '\0' ||
myGroups.count(serverData->getCommandGroup()) != 0 ||
myGroups.count("all") != 0)
{
count++;
packet.uByte2ToBuf(serverData->getCommand());
packet.strToBuf(serverData->getCommandGroup());
packet.strToBuf(serverData->getDataFlagsString());
}
}
// put the real number of entries in the right spot
//.........这里部分代码省略.........