Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/network/network_manager.cc @ 6541

Last change on this file since 6541 was 6341, checked in by bensch, 19 years ago

orxonox/trunk: merged the network branche back to the trunk, so we do not get away from each other to fast

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