コード例 #1
0
ファイル: TestUtils.cpp プロジェクト: bitfighter/bitfighter
S32 GamePair::getClientIndex(const string &name)
{
   for(S32 i = 0; i < getClientCount(); i++)
      if(strcmp(getClient(i)->getClientInfo()->getName().getString(), name.c_str()) == 0)
         return i;

   return NONE;
}
コード例 #2
0
ファイル: TestUtils.cpp プロジェクト: bitfighter/bitfighter
GameUserInterface *GamePair::getGameUI(S32 clientIndex)
{
   EXPECT_TRUE(clientIndex >= 0 && clientIndex < getClientCount()) << "Index out of bounds!";
   ClientGame *client = getClient(clientIndex);
   GameUserInterface *ui = dynamic_cast<GameUserInterface *>(client->getUIManager()->getCurrentUI());
   EXPECT_TRUE(ui != NULL) << "Are we in the game?";

   return ui;
}
コード例 #3
0
ファイル: server.c プロジェクト: jtdreisb/networks
void handleClient(struct ClientNode *client)
{
	ssize_t bytesRcvd;
	uint8_t *buf = malloc(MAX_PACKET_SIZE);
	if (buf == NULL) {
		perror("handleClient:malloc");
		return;
	}

	if ((bytesRcvd = recv(client->clientSocket, buf, MAX_PACKET_SIZE-1, 0)) < 0) {
		perror("handleClient:recv");
		free(buf);
		return;
	}
	// Check for a shutdown
	if (bytesRcvd == 0) {
		removeClient(client);
	}
	// Parse the buffer
	else {
		client->packetLength = bytesRcvd;
		client->packetData = (struct ChatHeader *)buf;
		// make sure the checksum is correct before parsing the packets
		if (in_cksum((uint16_t *)client->packetData, client->packetLength) == 0) {
			// Put the packet header fields in host order
			switch (client->packetData->flag) {
				case FLAG_INIT_REQ:
					registerHandle(client);
					break;
				case FLAG_MSG_REQ:
				case FLAG_MSG_ACK:
					forwardMessage(client);
					break;
				case FLAG_EXIT_REQ:
					clientExit(client);
					break;
				case FLAG_LIST_REQ:
					getClientCount(client);
					break;
				case FLAG_HNDL_REQ:
					clientNameRequest(client);
					break;
				case FLAG_INIT_ACK:
				case FLAG_INIT_ERR:
				case FLAG_MSG_ERR:
				case FLAG_EXIT_ACK:
				case FLAG_LIST_RESP:
				case FLAG_HNDL_RESP:
				default:
					break;
			}
		}
		client->packetData = NULL;
		client->packetLength = 0;
	}
	free(buf);
}