Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
networkcomm.h
Go to the documentation of this file.
1 #ifndef __NETWORKCOMM_H
2 #define __NETWORKCOMM_H
3 
4 #include "client.h"
5 #ifdef CRYPTO
6 #include <crypto++/randpool.h>
7 using namespace CryptoPP;
8 #endif
9 
10 #include "const.h"
11 #include "clientptr.h"
12 #include <string>
13 #include <list>
14 #include <deque>
15 #include "boost/shared_ptr.hpp"
16 #include <config.h>
17 
18 #ifdef NETCOMM_WEBCAM
19 class WebcamSupport;
20 #endif
21 
22 #ifdef NETCOMM_JVOIP
23 class JVOIPSession;
24 class JVOIPSessionParams;
25 class JVOIPRTPTransmissionParams;
26 #endif
27 
28 #ifdef NETCOMM_PORTAUDIO
29 #include <pa/portaudio.h>
30 #define MAX_PA_CPU_LOAD 0.5
31 //(MAX_PA_CPU_LOAD*100)% CPU LOAD
32 #endif
33 
36 
37 typedef std::list< ClientPtr >::iterator CltPtrIterator;
38 
39 class WebcamSupport;
40 
42 {
43 private:
44 //Text message
45  std::deque< std::string >message_history; //Text message history
46  unsigned short max_messages; //Maximum number of text messages recorded
47  std::list< ClientPtr > commClients; //List of client communicating on the same frequency
48  CltPtrIterator webcamClient; //The client we are watching the webcam
49 
50  char crypt_key[DESKEY_SIZE]; //Key used for encryption on secured channels
51  float min_freq, max_freq;
52  float freq; //Current communication frequency
53  bool active; //Tell wether the communication system is active
54  char secured; //Tell wether we are on a secured channel or not
55  unsigned char method; //Method used to spread comms
56 #ifdef NETCOMM_WEBCAM
57 //Webcam support
58  WebcamSupport *Webcam;
59  boost::shared_ptr< VsnetDownload::Client::Manager >_downloader;
60  boost::shared_ptr< VsnetDownload::Server::Manager >_downloadServer;
61  SocketSet _sock_set;
63 #endif
64 #ifdef NETCOMM_JVOIP
65  JVOIPSession *session;
66  JVOIPSessionParams *params;
67  JVOIPRTPTransmissionParams *rtpparams;
68 #endif
69 #ifdef NETCOMM_PORTAUDIO
70  PaDeviceID indev;
71  PaDeviceID outdev;
72  PaDeviceInfo *devinfo;
73  PortAudioStream *instream;
74  PortAudioStream *outstream;
75 
76  double sample_rate;
77  int audio_inlength;
78  unsigned short audio_inbuffer[MAXBUFFER];
79  unsigned short audio_outbuffer[MAXBUFFER];
80 
81  friend int Pa_RecordCallback( void *inputBuffer,
82  void *outputBuffer,
83  unsigned long framesPerBuffer,
84  PaTimestamp outTime,
85  void *userdata );
86  friend int Pa_PlayCallback( void *inputBuffer,
87  void *outputBuffer,
88  unsigned long framesPerBuffer,
89  PaTimestamp outTime,
90  void *userdata );
91 #endif
92 #ifdef CRYPTO
93 //Algorithm * cryptalgo;
94  RandomPool randPool;
95  std::string crypto_method;
96  std::string seed;
97  unsigned int key_length;
98  std::string pubKeyFilename;
99  std::string privKeyFilename;
100  std::string pubkey;
101  std::string privkey;
102 #endif
103 
104  void GenerateKey();
105  std::string EncryptBuffer( const char *buffer, unsigned int length = 0 );
106  std::string DecryptBuffer( const char *buffer, unsigned int length = 0 );
107 
108 public:
109  enum CommunicationMethod {ClientBroadcast, ServerUnicast};
110 
112  NetworkCommunication( float minfreq, float maxfreq, bool video, bool secured, std::string method );
113  NetworkCommunication( int nb );
115 
116  int InitSession( float frequency );
117 //void SendImage( SOCKETALT & send_sock);
118  void SendSound( SOCKETALT &send_sock, ObjSerial serial );
119  void SendMessage( SOCKETALT &send_sock, ObjSerial serial, std::string message );
120  void RecvSound( const char *sndbuffer, int length, bool encrypted = false );
121  void RecvMessage( std::string message, bool encrypted = false );
122  int DestroySession();
123 
124  void AddToSession( ClientPtr clt );
125  void RemoveFromSession( ClientPtr clt );
126 
127  bool IsActive()
128  {
129  return active;
130  }
131  char * GetWebcamCapture();
132  char * GetWebcamFromNetwork( int &length );
133  void StartWebcamTransfer();
134  void StopWebcamTransfer();
135 
136  char HasWebcam();
137  char HasPortaudio();
138 
139  char IsSecured()
140  {
141  return secured;
142  }
143  void SwitchSecured();
144  void SwitchWebcam();
145 
146  float MinFreq()
147  {
148  return this->min_freq;
149  }
150  float MaxFreq()
151  {
152  return this->max_freq;
153  }
154 
155 private:
156  void private_init();
157 };
158 
159 #endif
160