Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/network/src/lib/network/network_game_manager.cc @ 8024

Last change on this file since 8024 was 8024, checked in by rennerc, 18 years ago

added two missing files

File size: 4.2 KB
RevLine 
[6067]1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Benjamin Wuest
13   co-programmer: ...
14*/
15
16
17/* this is for debug output. It just says, that all calls to PRINT() belong to the DEBUG_MODULE_NETWORK module
18   For more information refere to https://www.orxonox.net/cgi-bin/trac.cgi/wiki/DebugOutput
19*/
20#define DEBUG_MODULE_NETWORK
21
[7193]22#include "util/loading/factory.h"
[7349]23#include "state.h"
24#include "class_list.h"
25
[6341]26#include "network_stream.h"
[7349]27#include "shared_network_data.h"
[6341]28#include "converter.h"
[7954]29#include "message_manager.h"
[6341]30
[6498]31#include "playable.h"
32#include "player.h"
[6424]33
[7349]34#include "game_world.h"
[6424]35
[7984]36#include "game_rules.h"
37#include "network_game_rules.h"
38
[6116]39#include "network_game_manager.h"
[6067]40
41
42/* using namespace std is default, this needs to be here */
43using namespace std;
44
[6341]45NetworkGameManager* NetworkGameManager::singletonRef = NULL;
46
[6067]47/*!
48 * Standard constructor
49 */
[6116]50NetworkGameManager::NetworkGameManager()
[6695]51  : Synchronizeable()
[6067]52{
[6341]53  PRINTF(0)("START\n");
54
[6067]55  /* set the class id for the base object */
[6341]56  this->setClassID(CL_NETWORK_GAME_MANAGER, "NetworkGameManager");
57
[6695]58  this->setSynchronized(true);
[8024]59 
60  MessageManager::getInstance()->registerMessageHandler( MSGID_DELETESYNCHRONIZEABLE, delSynchronizeableHandler, NULL );
[6067]61}
62
63/*!
64 * Standard destructor
65 */
[6116]66NetworkGameManager::~NetworkGameManager()
[6067]67{
68}
69
[6341]70
[7984]71/**
72 * insert new player into game
73 * @param userId
74 * @return
[6067]75 */
[7984]76bool NetworkGameManager::signalNewPlayer( int userId )
[6067]77{
[8014]78  assert( SharedNetworkData::getInstance()->isGameServer() );
79  assert( State::getGameRules() );
[7984]80  assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) );
[7954]81 
[7984]82  NetworkGameRules & rules = *(dynamic_cast<NetworkGameRules*>(State::getGameRules()));
[7954]83 
[7984]84  int team = rules.getTeamForNewUser();
85  ClassID playableClassId = rules.getPlayableClassId( team );
86  std::string playableModel = rules.getPlayableModelFileName( team, playableClassId );
[7954]87 
[7984]88  BaseObject * bo = Factory::fabricate( playableClassId );
[7954]89 
[8014]90  assert( bo != NULL );
[7984]91  assert( bo->isA( CL_PLAYABLE ) );
[7954]92 
[7984]93  Playable & playable = *(dynamic_cast<Playable*>(bo));
94 
95  playable.loadModel( playableModel );
[8014]96  playable.setOwner( userId );
97  playable.setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
98  playable.setSynchronized( true );
[7984]99 
100  PlayerStats * stats = rules.getNewPlayerStats( userId );
101 
[8014]102  stats->setUniqueID( SharedNetworkData::getInstance()->getNewUniqueID() );
103  stats->setSynchronized( true );
104  stats->setOwner( getHostID() );
105 
[7984]106  stats->setTeamId( team );
107  stats->setPlayableClassId( playableClassId );
108  stats->setPlayableUniqueId( playable.getUniqueID() );
109  stats->setModelFileName( playableModel );
[6341]110}
111
112
[6695]113/**
[7984]114 * remove player from game
115 * @param userID
116 * @return
[6695]117 */
[7984]118bool NetworkGameManager::signalLeftPlayer(int userID)
[6695]119{
120}
121
122
[7954]123
[8024]124/**
125 * handler for remove synchronizeable messages
126 * @param messageId
127 * @param data
128 * @param dataLength
129 * @param someData
130 * @param userId
131 * @return true on successfull handling else handler will be called again
132 */
133bool NetworkGameManager::delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId )
134{
135  if ( getInstance()->isServer() )
136  {
137    PRINTF(2)("Recieved DeleteSynchronizeable message from client %d!\n", userId);
138    return true;
139  }
140 
141  int uniqueId = 0;
142  int len = Converter::byteArrayToInt( data, &uniqueId );
143 
144  if ( len != dataLength )
145  {
146    PRINTF(2)("Recieved DeleteSynchronizeable message with incorrect size (%d) from client %d!\n", dataLength, userId);
147    return true;
148  }
149 
150  const std::list<BaseObject*> * list = ClassList::getList( CL_SYNCHRONIZEABLE );
151 
152  for ( std::list<BaseObject*>::const_iterator it = list->begin(); it != list->end(); it++ )
153  {
154    if ( dynamic_cast<Synchronizeable*>(*it)->getUniqueID() == uniqueId )
155    {
156      delete dynamic_cast<Synchronizeable*>(*it);
157      return true;
158    }
159  }
160}
[7954]161
[8024]162/**
163 * removes synchronizeable (also on clients)
164 * @param uniqueId uniqueid to delete
165 */
166void NetworkGameManager::removeSynchronizeable( int uniqueId )
167{
168}
[6341]169
170
171
[8024]172
173
Note: See TracBrowser for help on using the repository browser.