Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/osx/src/lib/network/network_manager.cc @ 7997

Last change on this file since 7997 was 7256, checked in by bensch, 19 years ago

orxonox/trunk: merged the preferences back to the trunk
merged with command:
svn merge https://svn.orxonox.net/orxonox/branches/preferences . -r7233:HEAD
no conflicts… nice work

File size: 3.8 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
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
22#include "class_list.h"
23#include "debug.h"
24#include "shell_command.h"
25
26/* include your own header */
27#include "network_manager.h"
28#include "shared_network_data.h"
29#include "network_stream.h"
30
31
32/* using namespace std is default, this needs to be here */
33using namespace std;
34
35SHELL_COMMAND(debug, NetworkManager, debug);
36
37
38NetworkManager* NetworkManager::singletonRef = NULL;
39
40/**
41 *  standard constructor
42 */
43NetworkManager::NetworkManager()
44{
45  /* set the class id for the base object */
46  this->setClassID(CL_NETWORK_MANAGER, "NetworkManager");
47  PRINTF(0)("START\n");
48
49  /* initialize the references */
50  this->netStreamList = NULL;
51  this->syncList = NULL;
52  this->defaultSyncStream = NULL;
53  this->sharedNetworkData = SharedNetworkData::getInstance();
54
55  PRINTF(0)("NetworkManager created\n");
56}
57
58
59/**
60 *  standard deconstructor
61 */
62NetworkManager::~NetworkManager()
63{}
64
65
66/**
67 *  initializes the network manager
68 */
69void NetworkManager::initialize()
70{
71  /* get the synchronizeable list from the class list */
72  this->netStreamList = ClassList::getList(CL_SYNCHRONIZEABLE);
73  PRINTF(0)("NetworkManager initzalized\n");
74}
75
76
77/**
78 *  shutsdown the network manager
79 */
80void NetworkManager::shutdown()
81{
82
83}
84
85
86/**
87 *  creates a connection from one object to a host
88 * @param hostName: the name of the destination host
89 */
90int NetworkManager::establishConnection(const std::string & name, unsigned int port)
91{
92  IPaddress ipAddress;
93  int error = SDLNet_ResolveHost(&ipAddress, name.c_str(), port);
94  if( error == -1) {
95    printf("\n\nerror on address resolution, program inconsistency\n\n");
96    return -1;
97  }
98
99  this->defaultSyncStream = new NetworkStream(ipAddress);
100  this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream);
101  this->defaultSyncStream->startHandshake();
102  return 1;
103}
104
105
106/**
107 *  creates a new NetworkStream of server type
108 * @param port: number of the TCP port
109 */
110int NetworkManager::createServer(unsigned int port)
111{
112  this->sharedNetworkData->setHostID(0);
113  this->sharedNetworkData->setGameServer(true);
114  this->defaultSyncStream = new NetworkStream(port);
115  this->sharedNetworkData->setDefaultSyncStream(this->defaultSyncStream);
116  this->defaultSyncStream->createNetworkGameManager();
117  PRINTF(0)("CREATE SERVER\n");
118  SDL_Delay(20);
119  return 1;
120}
121
122
123void NetworkManager::connectSynchronizeable(Synchronizeable& sync)
124{
125  if( this->defaultSyncStream)
126    this->defaultSyncStream->connectSynchronizeable(sync);
127}
128
129
130/**
131 *  sync the network
132 */
133void NetworkManager::synchronize()
134{
135  if (this->netStreamList != NULL || (this->netStreamList = ClassList::getList(CL_NETWORK_STREAM)) != NULL)
136  {
137    std::list<BaseObject*>::const_iterator stream;
138    for (stream = this->netStreamList->begin(); stream != this->netStreamList->end(); ++stream)
139      if( static_cast<NetworkStream*>(*stream)->isActive())
140        static_cast<NetworkStream*>(*stream)->processData();
141  }
142}
143
144
145
146/**
147 * debug output
148 */
149 void NetworkManager::debug()
150{
151  PRINT(0)("=================Network::debug()=========\n");
152  this->defaultSyncStream->debug();
153  PRINT(0)("===========================================\n");
154}
Note: See TracBrowser for help on using the repository browser.