send a different bird index to each subsequent assignee

This commit is contained in:
Stephen Birarda 2013-07-12 14:47:25 -07:00
parent 384dffc441
commit e1d7f752f2

View file

@ -29,13 +29,20 @@ int main(int argc, const char* argv[]) {
unsigned char assignmentPacket[numHeaderBytes + sizeof(char)];
populateTypeAndVersion(assignmentPacket, PACKET_TYPE_SEND_ASSIGNMENT);
int birdIndex = 0;
while (true) {
if (serverSocket.receive((sockaddr*) &senderSocket, &senderData, &receivedBytes)) {
if (senderData[0] == PACKET_TYPE_REQUEST_ASSIGNMENT) {
// for now just send back a dummy assignment packet
// pick a random number between 1 and 6 so the user grabs a random bird sound
assignmentPacket[numHeaderBytes] = randIntInRange(1, 7);
// give this assignee the next bird index
assignmentPacket[numHeaderBytes] = birdIndex++;
// wrap back to 0 if the bird index is 6 now
if (birdIndex == 6) {
birdIndex = 0;
}
// send the assignment
serverSocket.send((sockaddr*) &senderSocket, assignmentPacket, sizeof(assignmentPacket));