324 DLog(@"ERROR - wrong protocol number: %d (expecting %d)", netProto, eProto); |
329 DLog(@"ERROR - wrong protocol number: %d (expecting %d)", netProto, eProto); |
325 clientQuit = YES; |
330 clientQuit = YES; |
326 } |
331 } |
327 break; |
332 break; |
328 case 'i': |
333 case 'i': |
329 if (self.statsArray == nil) { |
334 if (statsArray == nil) { |
330 self.statsArray = [[NSMutableArray alloc] initWithCapacity:10 - 2]; |
335 statsArray = [[NSMutableArray alloc] initWithCapacity:10 - 2]; |
331 NSMutableArray *ranking = [[NSMutableArray alloc] initWithCapacity:4]; |
336 NSMutableArray *ranking = [[NSMutableArray alloc] initWithCapacity:4]; |
332 [self.statsArray insertObject:ranking atIndex:0]; |
337 [statsArray insertObject:ranking atIndex:0]; |
333 [ranking release]; |
338 [ranking release]; |
334 } |
339 } |
335 NSString *tempStr = [NSString stringWithUTF8String:&buffer[2]]; |
340 NSString *tempStr = [NSString stringWithUTF8String:&buffer[2]]; |
336 NSArray *info = [tempStr componentsSeparatedByString:@" "]; |
341 NSArray *info = [tempStr componentsSeparatedByString:@" "]; |
337 NSString *arg = [info objectAtIndex:0]; |
342 NSString *arg = [info objectAtIndex:0]; |
338 int index = [arg length] + 3; |
343 int index = [arg length] + 3; |
339 switch (buffer[1]) { |
344 switch (buffer[1]) { |
340 case 'r': // winning team |
345 case 'r': // winning team |
341 [self.statsArray insertObject:[NSString stringWithUTF8String:&buffer[2]] atIndex:1]; |
346 [statsArray insertObject:[NSString stringWithUTF8String:&buffer[2]] atIndex:1]; |
342 break; |
347 break; |
343 case 'D': // best shot |
348 case 'D': // best shot |
344 [self.statsArray addObject:[NSString stringWithFormat:@"The best shot award won by %s (with %@ points)", &buffer[index], arg]]; |
349 [statsArray addObject:[NSString stringWithFormat:@"The best shot award won by %s (with %@ points)", &buffer[index], arg]]; |
345 break; |
350 break; |
346 case 'k': // best hedgehog |
351 case 'k': // best hedgehog |
347 [self.statsArray addObject:[NSString stringWithFormat:@"The best killer is %s with %@ kill(s) in a turn", &buffer[index], arg]]; |
352 [statsArray addObject:[NSString stringWithFormat:@"The best killer is %s with %@ kill(s) in a turn", &buffer[index], arg]]; |
348 break; |
353 break; |
349 case 'K': // number of hogs killed |
354 case 'K': // number of hogs killed |
350 [self.statsArray addObject:[NSString stringWithFormat:@"%@ hedgehog(s) were killed during this round", arg]]; |
355 [statsArray addObject:[NSString stringWithFormat:@"%@ hedgehog(s) were killed during this round", arg]]; |
351 break; |
356 break; |
352 case 'H': // team health/graph |
357 case 'H': // team health/graph |
353 break; |
358 break; |
354 case 'T': // local team stats |
359 case 'T': // local team stats |
355 // still WIP in statsPage.cpp |
360 // still WIP in statsPage.cpp |
356 break; |
361 break; |
357 case 'P': // teams ranking |
362 case 'P': // teams ranking |
358 [[self.statsArray objectAtIndex:0] addObject:tempStr]; |
363 [[statsArray objectAtIndex:0] addObject:tempStr]; |
359 break; |
364 break; |
360 case 's': // self damage |
365 case 's': // self damage |
361 [self.statsArray addObject:[NSString stringWithFormat:@"%s thought it's good to shoot his own hedgehogs with %@ points", &buffer[index], arg]]; |
366 [statsArray addObject:[NSString stringWithFormat:@"%s thought it's good to shoot his own hedgehogs with %@ points", &buffer[index], arg]]; |
362 break; |
367 break; |
363 case 'S': // friendly fire |
368 case 'S': // friendly fire |
364 [self.statsArray addObject:[NSString stringWithFormat:@"%s killed %@ of his own hedgehogs", &buffer[index], arg]]; |
369 [statsArray addObject:[NSString stringWithFormat:@"%s killed %@ of his own hedgehogs", &buffer[index], arg]]; |
365 break; |
370 break; |
366 case 'B': // turn skipped |
371 case 'B': // turn skipped |
367 [self.statsArray addObject:[NSString stringWithFormat:@"%s was scared and skipped turn %@ times", &buffer[index], arg]]; |
372 [statsArray addObject:[NSString stringWithFormat:@"%s was scared and skipped turn %@ times", &buffer[index], arg]]; |
368 break; |
373 break; |
369 default: |
374 default: |
370 DLog(@"Unhandled stat message, see statsPage.cpp"); |
375 DLog(@"Unhandled stat message, see statsPage.cpp"); |
371 break; |
376 break; |
372 } |
377 } |
373 break; |
378 break; |
374 case 'q': |
379 case 'q': |
375 // game ended and match finished, statsArray is full of delicious statistics |
380 // game ended and match finished, statsArray is full of delicious statistics |
|
381 if (self.delegate != nil && [self.delegate respondsToSelector:@selector(gameEndedWithStatistics:)]) |
|
382 [self.delegate gameEndedWithStatistics:statsArray]; |
|
383 [statsArray release]; |
376 [HWUtils setGameStatus:gsEnded]; |
384 [HWUtils setGameStatus:gsEnded]; |
377 // closing connection here would trigger a "IPC connection lost" error, so we have to wait until recv fails |
385 // closing connection here would trigger a "IPC connection lost" error, so we have to wait until recv fails |
378 break; |
386 break; |
379 case 'Q': |
387 case 'Q': |
380 // game exited but not completed, skip this message in the savefile |
388 // game exited but not completed, skip this message in the savefile |