/[hegemonie]/hegemonie/Network/NetParty.m
ViewVC logotype

Diff of /hegemonie/Network/NetParty.m

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.11 by nicov, Wed Aug 13 12:41:23 2003 UTC revision 1.12 by nicov, Mon Aug 18 10:16:27 2003 UTC
# Line 82  Line 82 
82    
83    [[NSNotificationCenter defaultCenter] addObserver:self    [[NSNotificationCenter defaultCenter] addObserver:self
84                                          selector:@selector(createObject:)                                          selector:@selector(createObject:)
85                                          name:@"addObject" object:nil];                                          name:@"addObject" object: _game];
86    [[NSNotificationCenter defaultCenter] addObserver:self    [[NSNotificationCenter defaultCenter] addObserver:self
87                                          selector:@selector(destroyObject:)                                          selector:@selector(destroyObject:)
88                                          name:@"removeObject" object:nil];                                          name:@"removeObject" object: _game];
89    [[NSNotificationCenter defaultCenter] addObserver:self    [[NSNotificationCenter defaultCenter] addObserver:self
90                                          selector:@selector(addUpdatedObject:)                                          selector:@selector(addUpdatedObject:)
91                                          name:@"updateObject" object:nil];                                          name:@"updateObject" object: _game];
92    [[NSNotificationCenter defaultCenter] addObserver:self    [[NSNotificationCenter defaultCenter] addObserver:self
93                                          selector:@selector(createPlayer:)                                          selector:@selector(createPlayer:)
94                                          name:@"addPlayer" object:nil];                                          name:@"addPlayer" object: _game];
95    [[NSNotificationCenter defaultCenter] addObserver:self    [[NSNotificationCenter defaultCenter] addObserver:self
96                                          selector:@selector(destroyPlayer:)                                          selector:@selector(destroyPlayer:)
97                                          name:@"removePlayer" object:nil];                                          name:@"removePlayer" object: _game];
98    [[NSNotificationCenter defaultCenter] addObserver:self    [[NSNotificationCenter defaultCenter] addObserver:self
99                                          selector:@selector(updatePlayer:)                                          selector:@selector(updatePlayer:)
100                                          name:@"updatePlayer" object:nil];                                          name:@"updatePlayer" object: _game];
101    [[NSNotificationCenter defaultCenter] addObserver:self    [[NSNotificationCenter defaultCenter] addObserver:self
102                                          selector:@selector(createTeam:)                                          selector:@selector(createTeam:)
103                                          name:@"addTeam" object:nil];                                          name:@"addTeam" object:_game];
104    [[NSNotificationCenter defaultCenter] addObserver:self    [[NSNotificationCenter defaultCenter] addObserver:self
105                                          selector:@selector(destroyTeam:)                                          selector:@selector(destroyTeam:)
106                                          name:@"removeTeam" object:nil];                                          name:@"removeTeam" object:_game];
107    [[NSNotificationCenter defaultCenter] addObserver:self    [[NSNotificationCenter defaultCenter] addObserver:self
108                                          selector:@selector(updateTeam:)                                          selector:@selector(updateTeam:)
109                                          name:@"updateTeam" object:nil];                                          name:@"updateTeam" object:_game];
110        
111    return self;    return self;
112  }  }
# Line 231  Line 231 
231  /**  /**
232   * Connects the player named playerName to the NetParty   * Connects the player named playerName to the NetParty
233   * and returns the receive port on the server.   * and returns the receive port on the server.
234   * If the name is already in use, returns nil.   * If the name is already in use or if the number of player is already maximun,
235     * returns nil.
236   */   */
237  - (NSPort *) connectWithName: (NSString *)playerName  - (NSPort *) connectWithName: (NSString *)playerName
238                      withPort: (NSPort *)sendPort                      withPort: (NSPort *)sendPort
# Line 241  Line 242 
242    NSParameterAssert ([playerName length] != 0);    NSParameterAssert ([playerName length] != 0);
243    NSParameterAssert (sendPort);    NSParameterAssert (sendPort);
244        
245    if (![self containsPlayerName: playerName])    if (![self containsPlayerName: playerName] &&
246          [self numPlayers] < _maxNumPlayers)
247      {      {
248        NSPort *receivePort = [NSPort port];        NSPort *receivePort = [NSPort port];
249                
# Line 285  Line 287 
287   */   */
288  - (void) createObject:(NSNotification *)notification  - (void) createObject:(NSNotification *)notification
289  {  {
290    HgObject *obj = [notification object];    HgObject *obj = [[notification userInfo] objectForKey: @"HgObject"];
291        
292    NSEnumerator *enumerator = [_clients objectEnumerator];    NSEnumerator *enumerator = [_clients objectEnumerator];
293    NetInfosClient *client;    NetInfosClient *client;
# Line 308  Line 310 
310   */   */
311  - (void) destroyObject:(NSNotification *)notification  - (void) destroyObject:(NSNotification *)notification
312  {  {
313    HgObject *obj = [notification object];    HgObject *obj = [[notification userInfo] objectForKey: @"HgObject"];
314        
315    NSEnumerator *enumerator = [_clients objectEnumerator];    NSEnumerator *enumerator = [_clients objectEnumerator];
316    NetInfosClient *client;    NetInfosClient *client;
# Line 330  Line 332 
332   */   */
333  - (void) addUpdatedObject:(NSNotification *)notification  - (void) addUpdatedObject:(NSNotification *)notification
334  {  {
335    HgObject *obj = [notification object];    HgObject *obj = [[notification userInfo] objectForKey: @"HgObject"];
336      
337    unsigned i = [_updatedObjects indexOfObject: obj];    unsigned i = [_updatedObjects indexOfObject: obj];
338        
339    if (i != NSNotFound)    if (i != NSNotFound)
# Line 345  Line 347 
347   */   */
348  - (void) createPlayer:(NSNotification *)notification  - (void) createPlayer:(NSNotification *)notification
349  {  {
350    HgPlayer *player = [notification object];    HgPlayer *player = [[notification userInfo] objectForKey: @"HgPlayer"];
351        
352    NSEnumerator *enumerator = [_clients objectEnumerator];    NSEnumerator *enumerator = [_clients objectEnumerator];
353    NetInfosClient *client;    NetInfosClient *client;
# Line 360  Line 362 
362   */   */
363  - (void) destroyPlayer:(NSNotification *)notification  - (void) destroyPlayer:(NSNotification *)notification
364  {  {
365    HgPlayer *player = [notification object];    HgPlayer *player = [[notification userInfo] objectForKey: @"HgPlayer"];
366        
367    NSEnumerator *enumerator = [_clients objectEnumerator];    NSEnumerator *enumerator = [_clients objectEnumerator];
368    NetInfosClient *client;    NetInfosClient *client;
# Line 378  Line 380 
380   */   */
381  - (void) updatePlayer:(NSNotification *)notification  - (void) updatePlayer:(NSNotification *)notification
382  {  {
383    HgPlayer *player = [notification object];    HgPlayer *player = [[notification userInfo] objectForKey: @"HgPlayer"];
384        
385    NSEnumerator *enumerator = [_clients objectEnumerator];    NSEnumerator *enumerator = [_clients objectEnumerator];
386    NetInfosClient *client;    NetInfosClient *client;
# Line 394  Line 396 
396   */   */
397  - (void) createTeam:(NSNotification *)notification  - (void) createTeam:(NSNotification *)notification
398  {  {
399    HgTeam *team = [notification object];    HgTeam *team = [[notification userInfo] objectForKey: @"HgTeam"];  
400      
401    NSEnumerator *enumerator = [_clients objectEnumerator];    NSEnumerator *enumerator = [_clients objectEnumerator];
402    NetInfosClient *client;    NetInfosClient *client;
403    while ( (client = [enumerator nextObject]) )    while ( (client = [enumerator nextObject]) )
# Line 409  Line 411 
411   */   */
412  - (void) destroyTeam:(NSNotification *)notification  - (void) destroyTeam:(NSNotification *)notification
413  {  {
414    HgTeam *team = [notification object];    HgTeam *team = [[notification userInfo] objectForKey: @"HgTeam"];  
415        
416    NSEnumerator *enumerator = [_clients objectEnumerator];    NSEnumerator *enumerator = [_clients objectEnumerator];
417    NetInfosClient *client;    NetInfosClient *client;
# Line 424  Line 426 
426   */   */
427  - (void) updateTeam:(NSNotification *)notification  - (void) updateTeam:(NSNotification *)notification
428  {  {
429    HgTeam *team = [notification object];    HgTeam *team = [[notification userInfo] objectForKey: @"HgTeam"];  
430        
431    NSEnumerator *enumerator = [_clients objectEnumerator];    NSEnumerator *enumerator = [_clients objectEnumerator];
432    NetInfosClient *client;    NetInfosClient *client;
# Line 442  Line 444 
444   */   */
445  - (void) sendUpdatedObjects  - (void) sendUpdatedObjects
446  {  {
447    NSEnumerator *enumerator = [_updatedObjects objectEnumerator];    NSEnumerator *enum1 = [_updatedObjects objectEnumerator];
448    HgObject *obj;    HgObject *obj;
449    while ( (obj = [enumerator nextObject]) )    while ( (obj = [enum1 nextObject]) )
450      {      {
451        NSEnumerator *enumerator = [_clients objectEnumerator];        NSEnumerator *enum2 = [_clients objectEnumerator];
452        NetInfosClient *client;        NetInfosClient *client;
453        while ( (client = [enumerator nextObject]) )        while ( (client = [enum2 nextObject]) )
454          {          {
455            if ([[[client proxy] connectionForProxy] isValid])            if ([[[client proxy] connectionForProxy] isValid])
456              {              {

Legend:
Removed from v.1.11  
changed lines
  Added in v.1.12

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26