59 |
*/ |
*/ |
60 |
- (id) init |
- (id) init |
61 |
{ |
{ |
62 |
self = [super init]; |
self = [super init]; |
|
|
|
63 |
if (self != nil) |
if (self != nil) |
64 |
{ |
{ |
65 |
_gameList = AUTORELEASE ([NSMutableArray array]); |
_gameList = [[NSMutableArray init] alloc]; |
66 |
} |
} |
67 |
|
|
68 |
return self; |
return self; |
83 |
* Research games on the local network to actualise the list and returns |
* Research games on the local network to actualise the list and returns |
84 |
* this NetGameID list. |
* this NetGameID list. |
85 |
*/ |
*/ |
86 |
- (NSArray *) searchGames |
- (void) searchGames |
87 |
{ |
{ |
88 |
NSDistantObject<NetServer> *server; |
NSDistantObject<NetServer> *server; |
89 |
unsigned int num = 1; |
unsigned num = 1; |
|
unsigned int i; |
|
90 |
NSString *name; |
NSString *name; |
91 |
NSHost *host; |
NSHost *host; |
92 |
|
|
106 |
NSString *nameRegisteredForParty; |
NSString *nameRegisteredForParty; |
107 |
NSDistantObject<NetParty> * party; |
NSDistantObject<NetParty> * party; |
108 |
|
|
109 |
|
int i; |
110 |
for (i = 1; i <= [partyNameList count]; i++) |
for (i = 1; i <= [partyNameList count]; i++) |
111 |
{ |
{ |
112 |
nameRegisteredForParty = [NSString stringWithFormat: @"%@Party%d", |
nameRegisteredForParty = [NSString stringWithFormat: @"%@Party%d", |
115 |
party = [NetConnection rootProxyForConnectionWithRegisteredName: |
party = [NetConnection rootProxyForConnectionWithRegisteredName: |
116 |
nameRegisteredForParty |
nameRegisteredForParty |
117 |
host: @"*"]; |
host: @"*"]; |
118 |
[self _addGameIDWithParty: party |
[self _addGameIDWithParty: party |
119 |
withHost: host]; |
withHost: host]; |
120 |
} |
} |
121 |
} |
} |
122 |
} while (server != nil); |
} while (server != nil); |
123 |
|
} |
124 |
|
|
125 |
|
- (NSArray *) gameList |
126 |
|
{ |
127 |
return _gameList; |
return _gameList; |
128 |
} |
} |
129 |
|
|
132 |
* On success, returns the NetClient created. |
* On success, returns the NetClient created. |
133 |
* Else, if this player's name is already use by an other player, returns nil. |
* Else, if this player's name is already use by an other player, returns nil. |
134 |
*/ |
*/ |
135 |
- (NetClient *) connectToGame: (NetGameID *)gameID |
+ (NetClient *) connectToGame: (NetGameID *)gameID |
136 |
withName: (NSString *)playerName |
withName: (NSString *)playerName |
137 |
{ |
{ |
138 |
NSParameterAssert (gameID); |
NSParameterAssert (gameID); |
139 |
NSParameterAssert (playerName); |
NSParameterAssert (playerName); |
140 |
|
|
141 |
HgGame *game; |
HgGame *game; |
|
game = [[HgGame alloc] init]; |
|
142 |
|
|
143 |
NSPort *receivePort = [NSPort port]; |
NSPort *receivePort = [NSPort port]; |
144 |
|
|
|
printf(" - attente port\n"); |
|
145 |
NSPort *sendPort = [[gameID party] connectWithName: playerName |
NSPort *sendPort = [[gameID party] connectWithName: playerName |
146 |
withPort: receivePort |
withPort: receivePort |
147 |
initGame: &game]; |
initGame: &game]; |
|
printf(" - port renvoye\n"); |
|
148 |
|
|
149 |
RETAIN(game); |
RETAIN(game); |
150 |
|
|
161 |
withGame: game]; |
withGame: game]; |
162 |
|
|
163 |
[cnx setRootObject: client]; |
[cnx setRootObject: client]; |
164 |
[serverInfosClient createProxy]; |
[serverInfosClient registerClient]; |
|
[serverInfosClient delegateClient]; |
|
|
|
|
|
//RELEASE(game); |
|
165 |
|
|
166 |
return client; |
return client; |
167 |
} |
} |
168 |
else |
|
169 |
{ |
return nil; |
|
//RELEASE(game); |
|
|
return nil; |
|
|
} |
|
170 |
} |
} |
171 |
|
|
172 |
@end // End of NetGameList class implementation |
@end // End of NetGameList class implementation |