diff options
Diffstat (limited to 'libs/cocoslive/CLScoreServerRequest.h')
| -rwxr-xr-x | libs/cocoslive/CLScoreServerRequest.h | 122 |
1 files changed, 122 insertions, 0 deletions
| diff --git a/libs/cocoslive/CLScoreServerRequest.h b/libs/cocoslive/CLScoreServerRequest.h new file mode 100755 index 0000000..2002d4c --- /dev/null +++ b/libs/cocoslive/CLScoreServerRequest.h | |||
| @@ -0,0 +1,122 @@ | |||
| 1 | /* | ||
| 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org | ||
| 3 | * | ||
| 4 | * Copyright (c) 2008-2010 Ricardo Quesada | ||
| 5 | * Copyright (c) 2011 Zynga Inc. | ||
| 6 | * | ||
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 8 | * of this software and associated documentation files (the "Software"), to deal | ||
| 9 | * in the Software without restriction, including without limitation the rights | ||
| 10 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 11 | * copies of the Software, and to permit persons to whom the Software is | ||
| 12 | * furnished to do so, subject to the following conditions: | ||
| 13 | * | ||
| 14 | * The above copyright notice and this permission notice shall be included in | ||
| 15 | * all copies or substantial portions of the Software. | ||
| 16 | * | ||
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 18 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 19 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 20 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 21 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 23 | * THE SOFTWARE. | ||
| 24 | * | ||
| 25 | */ | ||
| 26 | |||
| 27 | |||
| 28 | |||
| 29 | #import <UIKit/UIKit.h> | ||
| 30 | |||
| 31 | // cocoslive definitions | ||
| 32 | #import "cocoslive.h" | ||
| 33 | |||
| 34 | // Server URL | ||
| 35 | #if USE_LOCAL_SERVER | ||
| 36 | #define SCORE_SERVER_REQUEST_URL @"http://localhost:8080/api/get-scores" | ||
| 37 | #define SCORE_SERVER_GETRANK_URL @"http://localhost:8080/api/get-rank-for-score" | ||
| 38 | #else | ||
| 39 | #define SCORE_SERVER_REQUEST_URL @"http://fourislandscores.appspot.com/api/get-scores" | ||
| 40 | #define SCORE_SERVER_GETRANK_URL @"http://fourislandscores.appspot.com/api/get-rank-for-score" | ||
| 41 | #endif | ||
| 42 | |||
| 43 | /** Type of predefined Query */ | ||
| 44 | typedef enum { | ||
| 45 | kQueryIgnore = 0, | ||
| 46 | kQueryDay = 1, | ||
| 47 | kQueryWeek = 2, | ||
| 48 | kQueryMonth = 3, | ||
| 49 | kQueryAllTime = 4, | ||
| 50 | } tQueryType; | ||
| 51 | |||
| 52 | /** Flags that can be added to the query */ | ||
| 53 | typedef enum { | ||
| 54 | kQueryFlagIgnore = 0, | ||
| 55 | kQueryFlagByCountry = 1 << 0, | ||
| 56 | kQueryFlagByDevice = 1 << 1, | ||
| 57 | } tQueryFlags; | ||
| 58 | |||
| 59 | /** | ||
| 60 | * Handles the Request Scores to the cocos live server | ||
| 61 | */ | ||
| 62 | @interface CLScoreServerRequest : NSObject { | ||
| 63 | |||
| 64 | /// game name, used as a login name. | ||
| 65 | NSString *gameName; | ||
| 66 | |||
| 67 | /// delegate instance of fetch score | ||
| 68 | id delegate; | ||
| 69 | |||
| 70 | // data received | ||
| 71 | NSMutableData *receivedData; | ||
| 72 | |||
| 73 | // To determine which delegate method will be called in connectionDidFinishLoading: of NSURLConnection Delegate | ||
| 74 | BOOL reqRankOnly; | ||
| 75 | |||
| 76 | /// the connection | ||
| 77 | NSURLConnection *connection_; | ||
| 78 | } | ||
| 79 | |||
| 80 | /** connection to the server */ | ||
| 81 | @property (nonatomic, retain) NSURLConnection *connection; | ||
| 82 | |||
| 83 | |||
| 84 | /** creates a ScoreServerRequest server with a game name*/ | ||
| 85 | +(id) serverWithGameName:(NSString*) name delegate:(id)delegate; | ||
| 86 | |||
| 87 | /** initializes a ScoreServerRequest with a game name*/ | ||
| 88 | -(id) initWithGameName:(NSString*) name delegate:(id)delegate; | ||
| 89 | |||
| 90 | /** request scores from server using a predefined query. This is an asyncronous request. | ||
| 91 | * limit: how many scores are being requested. Maximun is 100 | ||
| 92 | * flags: can be kQueryFlagByCountry (fetches only scores from country) | ||
| 93 | * category: an NSString. For example: 'easy', 'medium', 'type1'... When requesting scores, they can be filtered by this field. | ||
| 94 | */ | ||
| 95 | -(BOOL) requestScores: (tQueryType) type limit:(int)limit offset:(int)offset flags:(tQueryFlags)flags category:(NSString*)category; | ||
| 96 | |||
| 97 | /** request scores from server using a predefined query. This is an asyncronous request. | ||
| 98 | * limit: how many scores are being requested. Maximun is 100 | ||
| 99 | * flags: can be kQueryFlagByCountry (fetches only scores from country) | ||
| 100 | */ | ||
| 101 | -(BOOL) requestScores: (tQueryType) type limit:(int)limit offset:(int)offset flags:(tQueryFlags)flags; | ||
| 102 | |||
| 103 | /** parse the received JSON scores and convert it to objective-c objects */ | ||
| 104 | -(NSArray*) parseScores; | ||
| 105 | |||
| 106 | /** request rank for a given score using a predefined query. This is an asyncronous request. | ||
| 107 | * score: int for a score | ||
| 108 | * category: an NSString. For example: 'easy', 'medium', 'type1'... When requesting ranks, they can be filtered by this field. | ||
| 109 | */ | ||
| 110 | -(BOOL) requestRankForScore:(int)score andCategory:(NSString*)category; | ||
| 111 | |||
| 112 | /** It's actually not parsing anything, just returning int for a rank. Kept name PARSE for convinience with parseScores */ | ||
| 113 | -(int) parseRank; | ||
| 114 | |||
| 115 | @end | ||
| 116 | |||
| 117 | /** CocosLive Request protocol */ | ||
| 118 | @protocol CLRequestDelegate <NSObject> | ||
| 119 | -(void) scoreRequestOk:(id) sender; | ||
| 120 | -(void) scoreRequestRankOk:(id) sender; | ||
| 121 | -(void) scoreRequestFail:(id) sender; | ||
| 122 | @end | ||
