65 |
|
|
66 |
if (self != nil) |
if (self != nil) |
67 |
{ |
{ |
68 |
_party = RETAIN (party); |
_party = RETAIN(party); |
69 |
_connection = RETAIN (connection); |
_connection = RETAIN(connection); |
70 |
_isAdministrator = NO; |
_isAdministrator = NO; |
71 |
|
|
72 |
NSString *hostName; |
NSString *hostName; |
73 |
hostName = [[[connection sendPort] host] name]; |
hostName = [[[connection sendPort] host] name]; |
74 |
|
|
75 |
_player = AUTORELEASE ([[HgPlayer alloc] initWithName: name |
_player = [[HgPlayer alloc] initWithName: name |
76 |
user: NSUserName() |
user: NSUserName() |
77 |
host: hostName]); |
host: hostName]; |
78 |
|
|
79 |
_playerState = AUTORELEASE ([[HgPlayerState alloc] |
_playerState = [[HgPlayerState alloc] |
80 |
initWithPlayer: _player]); |
initWithPlayer: _player]; |
81 |
} |
} |
82 |
|
|
83 |
return self; |
return self; |
99 |
} |
} |
100 |
|
|
101 |
/** |
/** |
102 |
|
* FIXME - rework comments |
103 |
* Set the proxy associated with this object. |
* Set the proxy associated with this object. |
104 |
* Create the player on all the clients connected to the current game. |
* Create the player on all the clients connected to the current game. |
105 |
|
* Block other connections on the connection's receivePort of this object |
106 |
*/ |
*/ |
107 |
- (void) createProxy |
- (void) registerClient |
108 |
{ |
{ |
109 |
_proxy = RETAIN ([_connection rootProxy]); |
_proxy = RETAIN ([_connection rootProxy]); |
110 |
|
|
111 |
NSArray *clients; |
NSEnumerator *enumerator = [[_party clients] objectEnumerator]; |
112 |
clients = [[_party allClients] allValues]; |
NetInfosClient *client; |
113 |
int i; |
while ( (client = [enumerator nextObject]) ) |
|
|
|
|
for (i = 0; i < [[_party allClients] count]; i++) |
|
114 |
{ |
{ |
115 |
//do not send the createPlayer message to the current player |
[[client proxy] createPlayer: _player]; |
|
if( ![[[clients objectAtIndex: i] player] isEqualToPlayer: _player] ) |
|
|
{ |
|
|
[[[clients objectAtIndex: i] proxy] createPlayer: _player]; |
|
|
} |
|
116 |
} |
} |
117 |
|
|
118 |
// Interfacage avec HgGame |
NetConnection *defConnection = |
119 |
// problème : copier playerState sur le client |
[NetConnection connectionWithReceivePort: [_connection receivePort] |
120 |
// ------ FIXE ME ----------- |
sendPort: [_connection receivePort]]; |
121 |
|
[defConnection setDelegate: self]; |
122 |
} |
} |
123 |
|
|
124 |
/** |
/** |
131 |
} |
} |
132 |
|
|
133 |
/** |
/** |
|
* Block other connections on the connection's receivePort of this object |
|
|
*/ |
|
|
- (void) delegateClient |
|
|
{ |
|
|
NetConnection *defConnection = |
|
|
[NetConnection connectionWithReceivePort: [_connection receivePort] |
|
|
sendPort: [_connection receivePort]]; |
|
|
[defConnection setDelegate: self]; |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
134 |
* Disconnects the client from the current party. |
* Disconnects the client from the current party. |
135 |
*/ |
*/ |
136 |
- (void) disconnect |
- (void) disconnect |
137 |
{ |
{ |
138 |
NSArray *clients = [[_party allClients] allValues]; |
NSEnumerator *enumerator = [[_party clients] objectEnumerator]; |
139 |
int i; |
NetInfosClient *client; |
140 |
|
while ( (client = [enumerator nextObject]) ) |
|
for (i = 0; i < [clients count]; i++) |
|
141 |
{ |
{ |
142 |
printf(">>> Avant destruction\n"); |
if( client != self ) |
143 |
[[[clients objectAtIndex: i] proxy] destroyPlayer: _player]; |
{ |
144 |
printf(">>> Apres destruction\n"); |
[[client proxy] destroyPlayer: _player]; |
145 |
|
} |
146 |
} |
} |
147 |
|
|
|
//[_proxy destroyPlayer: _player]; |
|
|
|
|
148 |
[_party disconnect: self]; |
[_party disconnect: self]; |
149 |
} |
} |
150 |
|
|
151 |
|
- (HgPlayer *) player |
152 |
|
{ |
153 |
|
return _player; |
154 |
|
} |
155 |
|
|
156 |
/** |
/** |
157 |
* Updates the player's state |
* Updates the player's state |
158 |
*/ |
*/ |
159 |
- (void) updatePlayerState: (HgPlayerState *)playerState |
- (void) updatePlayerState: (HgPlayerState *)playerState |
160 |
{ |
{ |
|
/*----- FIX ME -----*/ |
|
|
|
|
161 |
NSParameterAssert (playerState); |
NSParameterAssert (playerState); |
162 |
|
|
163 |
_playerState = playerState; |
ASSIGN(_playerState, playerState); |
|
|
|
|
NSArray *clients = [[_party allClients] allValues]; |
|
|
int i; |
|
|
|
|
|
for (i = 0; i< [clients count]; i++) |
|
|
{ |
|
|
[[[clients objectAtIndex: i] proxy] updatePlayer: [_playerState player]]; |
|
|
} |
|
164 |
} |
} |
165 |
|
|
166 |
/** |
/** |
228 |
return _playerState; |
return _playerState; |
229 |
} |
} |
230 |
|
|
|
|
|
231 |
@end |
@end |