21 |
21 |
22 -(id) init { |
22 -(id) init { |
23 if (self = [super init]) { |
23 if (self = [super init]) { |
24 srandom(time(NULL)); |
24 srandom(time(NULL)); |
25 ipcPort = (random() % 64541) + 1025; |
25 ipcPort = (random() % 64541) + 1025; |
26 |
|
27 NSDictionary *hogA1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Snow Leopard",@"hogname",@"NoHat",@"hat",nil]; |
|
28 NSDictionary *hogA2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Leopard",@"hogname",@"NoHat",@"hat",nil]; |
|
29 NSArray *hedgehogs1 = [[NSArray alloc] initWithObjects:hogA1,hogA2,nil]; |
|
30 [hogA1 release]; |
|
31 [hogA2 release]; |
|
32 NSDictionary *firstTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4421353",@"color",@"0",@"hash",@"System Cats",@"teamname", |
|
33 @"star",@"grave",@"Earth",@"fort",@"Classic",@"voicepack",@"hedgewars",@"flag",hedgehogs1,@"hedgehogs", |
|
34 @"93919294221991210322351110012010000002111040400044140044464564444477477611221114440000000000000205500000040007004000000000213111103121111111231141111111111111112111", |
|
35 @"ammostore",nil]; |
|
36 [hedgehogs1 release]; |
|
37 |
|
38 NSDictionary *hogB1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Raichu",@"hogname",@"Bunny",@"hat",nil]; |
|
39 NSDictionary *hogB2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Pikachu",@"hogname",@"Bunny",@"hat",nil]; |
|
40 NSArray *hedgehogs2 = [[NSArray alloc] initWithObjects:hogB1,hogB2,nil]; |
|
41 [hogB1 release]; |
|
42 [hogB2 release]; |
|
43 NSDictionary *secondTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4100897",@"color",@"0",@"hash",@"Poke-MAN",@"teamname", |
|
44 @"Badger",@"grave",@"UFO",@"fort",@"Default",@"voicepack",@"hedgewars",@"flag",hedgehogs2,@"hedgehogs", |
|
45 @"93919294221991210322351110012010000002111040400044140044464564444477477611221114440000000000000205500000040007004000000000213111103121111111231141111111111111112111", |
|
46 @"ammostore",nil]; |
|
47 [hedgehogs2 release]; |
|
48 |
|
49 teams = [[NSArray alloc] initWithObjects: firstTeam, secondTeam, nil]; |
|
50 [firstTeam release]; |
|
51 [secondTeam release]; |
|
52 |
26 |
53 NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"]; |
27 NSString *filePath = [[SDLUIKitDelegate sharedAppDelegate] dataFilePath:@"settings.plist"]; |
54 systemSettings = [[NSDictionary alloc] initWithContentsOfFile:filePath]; //should check it exists |
28 systemSettings = [[NSDictionary alloc] initWithContentsOfFile:filePath]; //should check it exists |
55 return self; |
29 return self; |
56 } else |
30 } else |
69 SEL usage = NSSelectorFromString(selector); |
43 SEL usage = NSSelectorFromString(selector); |
70 [NSThread detachNewThreadSelector:usage toTarget:self withObject:nil]; |
44 [NSThread detachNewThreadSelector:usage toTarget:self withObject:nil]; |
71 } |
45 } |
72 |
46 |
73 -(int) sendToEngine: (NSString *)string { |
47 -(int) sendToEngine: (NSString *)string { |
74 Uint8 length = [string length]; |
48 unsigned char length = [string length]; |
75 |
49 |
76 SDLNet_TCP_Send(csd, &length , 1); |
50 SDLNet_TCP_Send(csd, &length , 1); |
77 return SDLNet_TCP_Send(csd, [string UTF8String], length); |
51 return SDLNet_TCP_Send(csd, [string UTF8String], length); |
78 } |
52 } |
79 |
53 |
80 -(void) sendTeamData:(NSDictionary *)teamData { |
54 -(void) initTeam:(NSArray *)teamLists { |
|
55 teams = [[NSMutableArray alloc] initWithObjects:nil]; |
|
56 |
|
57 for (NSString *teamString in teamLists) { |
|
58 //NSString *teamFile = [[NSString alloc] initWithFormat:@"%@.plist", teamString]; |
|
59 |
|
60 //NSDictionary *theTeam = [[NSDictionary alloc] initWithContentsOfFile:filePath]; |
|
61 //[teams addObject:theTeam]; |
|
62 //[theTeam release]; |
|
63 } |
|
64 |
|
65 NSDictionary *hogA1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Snow Leopard",@"hogname",@"NoHat",@"hat",nil]; |
|
66 NSDictionary *hogA2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Leopard",@"hogname",@"NoHat",@"hat",nil]; |
|
67 NSArray *hedgehogs1 = [[NSArray alloc] initWithObjects:hogA1,hogA2,nil]; |
|
68 [hogA1 release]; |
|
69 [hogA2 release]; |
|
70 NSDictionary *firstTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4421353",@"color",@"0",@"hash",@"System Cats",@"teamname", |
|
71 @"star",@"grave",@"Earth",@"fort",@"Classic",@"voicepack",@"hedgewars",@"flag",hedgehogs1,@"hedgehogs", |
|
72 @"93919294221991210322351110012010000002111040400044140044464564444477477611221114440000000000000205500000040007004000000000213111103121111111231141111111111111112111", |
|
73 @"ammostore",nil]; |
|
74 [hedgehogs1 release]; |
|
75 [teams addObject:firstTeam]; |
|
76 [firstTeam release]; |
|
77 |
|
78 NSDictionary *hogB1 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Raichu",@"hogname",@"Bunny",@"hat",nil]; |
|
79 NSDictionary *hogB2 = [[NSDictionary alloc] initWithObjectsAndKeys:@"100",@"health",@"0",@"level",@"Pikachu",@"hogname",@"Bunny",@"hat",nil]; |
|
80 NSArray *hedgehogs2 = [[NSArray alloc] initWithObjects:hogB1,hogB2,nil]; |
|
81 [hogB1 release]; |
|
82 [hogB2 release]; |
|
83 NSDictionary *secondTeam = [[NSDictionary alloc] initWithObjectsAndKeys:@"4100897",@"color",@"0",@"hash",@"Poke-MAN",@"teamname", |
|
84 @"Badger",@"grave",@"UFO",@"fort",@"Default",@"voicepack",@"hedgewars",@"flag",hedgehogs2,@"hedgehogs", |
|
85 @"93919294221991210322351110012010000002111040400044140044464564444477477611221114440000000000000205500000040007004000000000213111103121111111231141111111111111112111", |
|
86 @"ammostore",nil]; |
|
87 [hedgehogs2 release]; |
|
88 [teams addObject:secondTeam]; |
|
89 [secondTeam release]; |
|
90 } |
|
91 |
|
92 -(void) sendTeamData:(NSDictionary *)teamData withPlayingHogs:(int) playingHogs{ |
|
93 int i; |
|
94 |
81 NSString *teamHashColorAndName = [[NSString alloc] initWithFormat:@"eaddteam %@ %@ %@", [teamData objectForKey:@"hash"], [teamData objectForKey:@"color"], [teamData objectForKey:@"teamname"]]; |
95 NSString *teamHashColorAndName = [[NSString alloc] initWithFormat:@"eaddteam %@ %@ %@", [teamData objectForKey:@"hash"], [teamData objectForKey:@"color"], [teamData objectForKey:@"teamname"]]; |
82 [self sendToEngine: teamHashColorAndName]; |
96 [self sendToEngine: teamHashColorAndName]; |
83 [teamHashColorAndName release]; |
97 [teamHashColorAndName release]; |
84 |
98 |
85 NSString *grave = [[NSString alloc] initWithFormat:@"egrave %@", [teamData objectForKey:@"grave"]]; |
99 NSString *grave = [[NSString alloc] initWithFormat:@"egrave %@", [teamData objectForKey:@"grave"]]; |
97 NSString *flag = [[NSString alloc] initWithFormat:@"eflag %@", [teamData objectForKey:@"flag"]]; |
111 NSString *flag = [[NSString alloc] initWithFormat:@"eflag %@", [teamData objectForKey:@"flag"]]; |
98 [self sendToEngine: flag]; |
112 [self sendToEngine: flag]; |
99 [flag release]; |
113 [flag release]; |
100 |
114 |
101 NSArray *hogs = [teamData objectForKey:@"hedgehogs"]; |
115 NSArray *hogs = [teamData objectForKey:@"hedgehogs"]; |
102 for (NSDictionary *hog in hogs) { |
116 for (i = 0; i < playingHogs; i++) { |
|
117 NSDictionary *hog = [hogs objectAtIndex:i]; |
|
118 |
103 NSString *hogLevelHealthAndName = [[NSString alloc] initWithFormat:@"eaddhh %@ %@ %@", [hog objectForKey:@"level"], [hog objectForKey:@"health"], [hog objectForKey:@"hogname"]]; |
119 NSString *hogLevelHealthAndName = [[NSString alloc] initWithFormat:@"eaddhh %@ %@ %@", [hog objectForKey:@"level"], [hog objectForKey:@"health"], [hog objectForKey:@"hogname"]]; |
104 [self sendToEngine: hogLevelHealthAndName]; |
120 [self sendToEngine: hogLevelHealthAndName]; |
105 [hogLevelHealthAndName release]; |
121 [hogLevelHealthAndName release]; |
106 |
122 |
107 NSString *hogHat = [[NSString alloc] initWithFormat:@"ehat %@", [hog objectForKey:@"hat"]]; |
123 NSString *hogHat = [[NSString alloc] initWithFormat:@"ehat %@", [hog objectForKey:@"hat"]]; |
158 gameTicks = SDLNet_Read16(&buffer[msgSize - 2]); |
174 gameTicks = SDLNet_Read16(&buffer[msgSize - 2]); |
159 //NSLog(@"engineProtocol - %d: received [%s]", gameTicks, buffer); |
175 //NSLog(@"engineProtocol - %d: received [%s]", gameTicks, buffer); |
160 |
176 |
161 if ('C' == buffer[0]) { |
177 if ('C' == buffer[0]) { |
162 NSLog(@"engineProtocol - sending game config"); |
178 NSLog(@"engineProtocol - sending game config"); |
163 |
179 |
|
180 NSArray *teamlist = [[NSArray alloc] initWithObjects:@"this",@"is",@"test",nil]; |
|
181 [self initTeam:teamlist]; |
|
182 [teamlist release]; |
|
183 |
164 // send config data data |
184 // send config data data |
165 /* |
185 /* |
166 seed is arbitrary string |
186 seed is arbitrary string |
167 addteam <32charsMD5hash> <color> <team name> |
187 addteam <32charsMD5hash> <color> <team name> |
168 addhh <level> <health> <hedgehog name> |
188 addhh <level> <health> <hedgehog name> |
226 break; |
246 break; |
227 case 'e': |
247 case 'e': |
228 sscanf(buffer, "%*s %d", &eProto); |
248 sscanf(buffer, "%*s %d", &eProto); |
229 short int netProto; |
249 short int netProto; |
230 char *versionStr; |
250 char *versionStr; |
231 /* |
251 |
232 HW_versionInfo(&netProto, &versionStr); |
252 HW_versionInfo(&netProto, &versionStr); |
233 if (netProto == eProto) { |
253 if (netProto == eProto) { |
234 NSLog(@"Setting protocol version %d (%s)", eProto, versionStr); |
254 NSLog(@"Setting protocol version %d (%s)", eProto, versionStr); |
235 } else { |
255 } else { |
236 NSLog(@"ERROR - wrong protocol number: [%s] - expecting %d", buffer, eProto); |
256 NSLog(@"ERROR - wrong protocol number: [%s] - expecting %d", buffer, eProto); |
237 clientQuit = YES; |
257 clientQuit = YES; |
238 } |
258 } |
239 */ |
259 |
240 break; |
260 break; |
241 case 'i': |
261 case 'i': |
242 switch (buffer[1]) { |
262 switch (buffer[1]) { |
243 case 'r': |
263 case 'r': |
244 NSLog(@"Winning team: %s", &buffer[2]); |
264 NSLog(@"Winning team: %s", &buffer[2]); |