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