summary refs log tree commit diff stats
path: root/libs/cocoslive/CLScoreServerPost.h
diff options
context:
space:
mode:
authorStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
committerStarla Insigna <starla4444@gmail.com>2011-07-30 11:19:14 -0400
commit9cd57b731ab1c666d4a1cb725538fdc137763d12 (patch)
tree5bac45ae5157a1cb10c6e45500cbf72789917980 /libs/cocoslive/CLScoreServerPost.h
downloadcartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.gz
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.tar.bz2
cartcollect-9cd57b731ab1c666d4a1cb725538fdc137763d12.zip
Initial commit (version 0.2.1)
Diffstat (limited to 'libs/cocoslive/CLScoreServerPost.h')
-rwxr-xr-xlibs/cocoslive/CLScoreServerPost.h142
1 files changed, 142 insertions, 0 deletions
diff --git a/libs/cocoslive/CLScoreServerPost.h b/libs/cocoslive/CLScoreServerPost.h new file mode 100755 index 0000000..e782b90 --- /dev/null +++ b/libs/cocoslive/CLScoreServerPost.h
@@ -0,0 +1,142 @@
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// for MD5 signing
32#import <CommonCrypto/CommonDigest.h>
33
34// cocoslive definitions
35#import "cocoslive.h"
36
37// Score Server protocol version
38#define SCORE_SERVER_PROTOCOL_VERSION @"1.1"
39
40// Server URL
41#ifdef USE_LOCAL_SERVER
42#define SCORE_SERVER_SEND_URL @"http://localhost:8080/api/post-score"
43#define SCORE_SERVER_UPDATE_URL @"http://localhost:8080/api/update-score"
44#else
45#define SCORE_SERVER_SEND_URL @"http://fourislandscores.appspot.com/api/post-score"
46#define SCORE_SERVER_UPDATE_URL @"http://fourislandscores.appspot.com/api/update-score"
47#endif
48
49/// Type of errors from the Post Score request
50typedef enum {
51 /// post request successful
52 kPostStatusOK = 0,
53 /// post request failed to establish a connection. wi-fi isn't enabled.
54 /// Don't retry when this option is preset
55 kPostStatusConnectionFailed = 1,
56 /// post request failed to post the score. Server might be busy.
57 /// Retry is suggested
58 kPostStatusPostFailed = 2,
59} tPostStatus;
60
61enum {
62 //! Invalid Ranking. Valid rankins are from 1 to ...
63 kServerPostInvalidRanking = 0,
64};
65
66/**
67 * Handles the Score Post to the cocos live server
68 */
69@interface CLScoreServerPost : NSObject {
70 /// game key. secret shared with the server.
71 /// used to sign the values to prevent spoofing.
72 NSString *gameKey;
73
74 /// game name, used as a login name.
75 NSString *gameName;
76
77 /// delegate instance of fetch score
78 id delegate;
79
80 /// ranking
81 NSUInteger ranking_;
82
83 /// score was updated
84 BOOL scoreDidUpdate_;
85
86 /// data received
87 NSMutableData *receivedData;
88
89 /// values to send in the POST
90 NSMutableArray *bodyValues;
91
92 /// status of the request
93 tPostStatus postStatus_;
94
95 /// mdt context
96 CC_MD5_CTX md5Ctx;
97
98 /// the connection
99 NSURLConnection *connection_;
100}
101
102/** status from the score post */
103@property (nonatomic,readonly) tPostStatus postStatus;
104
105/** connection to the server */
106@property (nonatomic, retain) NSURLConnection *connection;
107
108/** ranking of your score
109 @since v0.7.3
110 */
111@property (nonatomic,readonly) NSUInteger ranking;
112
113/** whether or not the score was updated
114 @since v0.7.3
115 */
116@property (nonatomic,readonly) BOOL scoreDidUpdate;
117
118/** creates a cocos server with a game name and a game key */
119+(id) serverWithGameName:(NSString*) name gameKey:(NSString*) key delegate:(id)delegate;
120
121/** initializes a cocos server with a game name and a game key */
122-(id) initWithGameName:(NSString*) name gameKey:(NSString*) key delegate:(id)delegate;
123
124/** send the scores to the server. A new entre will be created on the server */
125-(BOOL) sendScore: (NSDictionary*) dict;
126
127/**
128 * Sends a score dictionary to the server for updating an existing entry by playername and device id, or creating a new one.
129 * The passed dictionary must contain a cc_playername key, otherwise it will raise and exception.
130 * @since v0.7.1
131 */
132-(BOOL) updateScore: (NSDictionary*) dict;
133
134@end
135
136/** CocosLivePost protocol */
137@protocol CLPostDelegate <NSObject>
138/** callback method that will be called if the post is successful */
139-(void) scorePostOk:(id) sender;
140/** callback method that will be called if the post fails */
141-(void) scorePostFail:(id) sender;
142@end