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

Diff of /hegemonie/Network/NetServer.m

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

revision 1.5 by nicov, Tue Jun 10 15:57:33 2003 UTC revision 1.6 by thunder, Thu Jul 17 16:27:32 2003 UTC
# Line 40  Line 40 
40   * This object must to vended afer this initialization, and before to call   * This object must to vended afer this initialization, and before to call
41   * an other method of this object.   * an other method of this object.
42   * The list of games is empty.   * The list of games is empty.
  *  
43   */   */
44  - (id) initWithRegisteredName: (NSString *)name  - (id) initWithRegisteredName: (NSString *)name
45  {  {
46    NSParameterAssert (name);    NSParameterAssert (name);
47        
48    self = [super init];    self = [super init];
   
49    if (self != nil)    if (self != nil)
50      {      {
51        _partyList =       AUTORELEASE ([NSMutableDictionary dictionary]);        _partyList = [[NSMutableDictionary alloc] init];
52        _registreredName = RETAIN (name);        _registreredName = RETAIN (name);
53      }      }
54    
# Line 72  Line 70 
70  /**  /**
71   * Vend an object "party" for a new connection with a registered name.   * Vend an object "party" for a new connection with a registered name.
72   */   */
73  void  static void
74  registerName (NSString *registeredName, NetParty *party)  _registerName (NSString *registeredName, NetParty *party)
75  {  {
76    NetConnection  *connexion;    NetConnection  *connexion;
77    NSPort         *port;    NSPort         *port;
# Line 99  registerName (NSString *registeredName, Line 97  registerName (NSString *registeredName,
97    NSParameterAssert (gameName);    NSParameterAssert (gameName);
98    NSParameterAssert (![gameName isEqualToString: @""]);    NSParameterAssert (![gameName isEqualToString: @""]);
99        
100    NSException *myException = [NSException    NetParty *newParty
101                                 exceptionWithName:@"gameNameException"      = [[NetParty alloc] initWithName: gameName
102                                 reason:@"gameName already exists"                              inServer: self];
                                userInfo:nil];  
     
   if ([_partyList objectForKey: gameName] != nil)  
     [myException raise];  
     
   NetParty *newParty;  
     
   newParty = AUTORELEASE ([[NetParty alloc] initWithName: gameName  
                                                 inServer: self]);  
103    
104    [_partyList setObject: newParty forKey: gameName];    [self addParty: newParty];
105      RELEASE(newParty);
106     NSString  *nameForRegister;  }
107     nameForRegister = [NSString stringWithFormat: @"%@Party%d",    
                                _registreredName, [_partyList count]];  
                                 
    registerName (nameForRegister, newParty);  
 }    
108    
109  /**  /**
110   * Add a existing game "NetParty" to the list.   * Add a existing game "NetParty" to the list.
# Line 127  registerName (NSString *registeredName, Line 112  registerName (NSString *registeredName,
112   * present in the list. If it's the case, an exception "gameNameException"   * present in the list. If it's the case, an exception "gameNameException"
113   * is raised.   * is raised.
114   */   */
115  - (void) addParty: (NetParty *)game  - (void) addParty: (NetParty *)party
116  {  {
117    NSParameterAssert (game);    NSParameterAssert (party);
118        
119    NSException *myException = [NSException    NSException *myException = [NSException
120                                 exceptionWithName:@"gameNameException"                                 exceptionWithName:@"partyNameException"
121                                 reason:@"gameName already exists"                                 reason:@"partyName already exists"
122                                 userInfo:nil];                                 userInfo:nil];
123        
124    if ([_partyList objectForKey: [game name]] != nil)    if ([_partyList objectForKey: [party gameName]] != nil)
125      [myException raise];      [myException raise];
126        
127    [_partyList setObject: game forKey: [game name]];    [_partyList setObject: party forKey: [party gameName]];
128    
129    NSString  *nameForRegister;    NSString  *nameForRegister;
130    nameForRegister = [NSString stringWithFormat: @"%@Party%d",    nameForRegister = [NSString stringWithFormat: @"%@Party%d",
131                                _registreredName, [_partyList count]];                                _registreredName, [_partyList count]];
132        
133    registerName (nameForRegister, game);    _registerName (nameForRegister, party);
134  }    }  
135    
136  /**  /**
137   * Remove an existing game "NetParty" in the list.   * Remove an existing party "NetParty" in the list.
138   * If the game does not exist, do nothing.   * If the party does not exist, do nothing.
139   */   */
140  - (void) removeParty: (NetParty *)game  - (void) removeParty: (NetParty *)party
141  {  {
142    NSParameterAssert (game);    NSParameterAssert (party);
143    
144    [_partyList removeObjectForKey: [game name]];    [_partyList removeObjectForKey: [party gameName]];
145  }  }
146    
147  /**  /**

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

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