/* -*- Objc -*- */ /* * $Id: NetInfosClient.m,v 1.1 2003/05/26 10:21:21 thunder Exp $ * * Copyright (C) 2003 Free Software Foundation, Inc. * * This file is part of GNU Hégémonie. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include #include #include #include #include "Network/NetParty.h" #include "Network/NetInfosClient.h" #include "Network/NetConnection.h" #include "GameEngine/HgPlayer.h" #include "GameEngine/HgPlayerState.h" /** * This class represents the informations for a client on the server. * */ @implementation NetInfosClient /** * Initialise NetInfosClient with an existing NetParty and with * the connection used by the client to communicate with the server. * The NetClient associated with this object is not initialised yet. * You have to initialise it after. */ - (id) initWithParty: (NetParty *)party withProxy: (NSDistantObject *)proxy playerName: (NSString *)name { NSParameterAssert (party); NSParameterAssert (proxy); NSParameterAssert (name); NSParameterAssert ([name length] != 0); self = [super init]; if (self != nil) { _party = RETAIN(party); _proxy = RETAIN(proxy); //_host = RETAIN(host); _isAdministrator = NO; /*----- FIXME -----*/ _player = AUTORELEASE([[HgPlayer alloc] initWithName: name user: NSUserName() host: @"address"]); //[host name] _playerState = AUTORELEASE([[HgPlayerState alloc] initWithPlayer: _player]); // créer joueur chez tous les clients } return self; } /** * Release NetInfosClient. */ - (void) dealloc { RELEASE(_party); RELEASE(_proxy); // RELEASE(_host); RELEASE(_player); RELEASE(_playerState); [super dealloc]; } /** * This will disconnect the client from the current party. */ - (void) disconnect { NSArray *clients = [[_party allClients] allValues]; int i; for (i = 0; i< [clients count]; i++) { [[[clients objectAtIndex: i] proxy] destroyPlayer: _player]; } [_party disconnect: self]; } /** * This will update the player's state */ - (void) updatePlayerState: (HgPlayerState *)playerState { /*----- FIX ME -----*/ NSParameterAssert (playerState); _playerState = playerState; NSArray *clients = [[_party allClients] allValues]; int i; for (i = 0; i< [clients count]; i++) { [[[clients objectAtIndex: i] proxy] updatePlayer: [_playerState player]]; } } /** * This will send command to the server * command will be executed only if the client who send it is administrator */ - (NSString *) execCommand: (NSString *)command { NSParameterAssert (command); /*----- FIXME -----*/ return nil; } /** * This will send message to the server, to communicate between * players of the same team. */ - (void) talk: (NSString *)message { NSParameterAssert (message); /*----- FIXME -----*/ } /** * This will change the permission of the client * if flag is TRUE then the client becomes an administrator. */ - (void) setAdministrator: (BOOL)flag { _isAdministrator = flag; } /** * Returns the permission of the client (administrator or not). */ - (BOOL) isAdministrator { return _isAdministrator; } /** * Returns the distant object (= the client) */ - (NSDistantObject *)proxy { return _proxy; } /** * Returns the player associated with the client. */ - (HgPlayer*) player { return _player; } /** * Returns the playerState associated with the client. */ - (HgPlayerState*) playerState { return _playerState; } /** * This is a method of the delegate object. */ - (BOOL) connection: (NetConnection *)parent shouldMakeNewConnection: (NetConnection *)newConnection { return NO; } @end