Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/proxy/src/lib/network/proxy/proxy_control.cc @ 9560

Last change on this file since 9560 was 9557, checked in by patrick, 18 years ago

found the bug, now the network should work :D

File size: 3.2 KB
Line 
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: Patrick Boenzli (patrick@orxonox.ethz.ch)
13*/
14
15#include "proxy_control.h"
16
17#include "class_list.h"
18
19
20#include "player.h"
21#include "state.h"
22#include "shared_network_data.h"
23#include "network_game_manager.h"
24
25#include "converter.h"
26
27#include "preferences.h"
28
29#include "debug.h"
30
31
32
33
34ProxyControl* ProxyControl::singletonRef = NULL;
35
36
37/**
38 * constructor
39 */
40ProxyControl::ProxyControl()
41{
42  this->setClassID( CL_PROXY_CONTROL, "ProxyControl" );
43
44  MessageManager::getInstance()->registerMessageHandler( MSGID_PROXY_NEWCLIENT, messageHandlerNewClient, NULL );
45
46  PRINTF(0)("ProxyControl created\n");
47}
48
49
50/**
51 * standard deconstructor
52 */
53ProxyControl::~ProxyControl()
54{
55  ProxyControl::singletonRef = NULL;
56}
57
58
59 /**
60 * override this function to be notified on change
61 * of your registred variables.
62 * @param id id's which have changed
63  */
64void ProxyControl::varChangeHandler( std::list< int > & id )
65{
66//   if ( std::find( id.begin(), id.end(), playableUniqueId_handle ) != id.end() )
67//   {
68//     this->setPlayableUniqueId( this->playableUniqueId );
69//
70//     PRINTF(0)("uniqueID changed %d %d %d\n", userId, SharedNetworkData::getInstance()->getHostID(), getUniqueID());
71//   }
72}
73
74
75/**
76 *  signals new client connected to this local proxy
77 * @param userId userId of the new client
78 */
79void ProxyControl::signalNewClient(int userId)
80{
81  PRINTF(0)("Signaling new Client: %i\n", userId);
82  // make sure we are a proxy server
83  assert(SharedNetworkData::getInstance()->isProxyServerActive());
84
85  byte data[INTSIZE];
86
87  assert( Converter::intToByteArray( userId, data, INTSIZE ) == INTSIZE );
88
89  MessageManager::getInstance()->sendMessage( MSGID_PROXY_NEWCLIENT, data, INTSIZE, RT_SERVER, NET_UNASSIGNED, MP_HIGHBANDWIDTH );
90}
91
92
93/**
94 * this is the handler for proxy signals: new clients
95 *
96 * @param messageType the type of the message
97 * @param data message data
98 * @param dataLength length of the message data
99 * @param someData some other atteched data
100 * @param senderId id of the sender client
101 * @param destinationId id of the destination client
102 * @return true if succeeded
103 */
104bool ProxyControl::messageHandlerNewClient( MessageType messageType, byte * data, int dataLength, void * someData, int senderId, int destinationId  )
105{
106  // body data length correct?
107  if ( dataLength != INTSIZE )
108  {
109    PRINTF(2)("new client message has wrong size: %d\n", dataLength );
110    return true;
111  }
112  // read the userId fromt he message body
113  int newClientId = 0;
114  assert( Converter::byteArrayToInt( data, &newClientId) == INTSIZE );
115
116  PRINTF(0)("Got Signal: from %i new player arrived with userId: %i\n", senderId, newClientId);
117  // part for the master server
118  if( SharedNetworkData::getInstance()->isMasterServer())
119  {
120    // we now create the new player ship and stuff...
121    NetworkGameManager::getInstance()->signalNewPlayer(newClientId);
122  }
123  else if(SharedNetworkData::getInstance()->isProxyServerActive())
124  {
125
126  }
127
128  return true;
129}
Note: See TracBrowser for help on using the repository browser.