1 | /*! |
---|
2 | * @file network_stream.h |
---|
3 | * implementation of a network pipe. This node handles the handshake of two network nodes and exchanges informationas |
---|
4 | * vial to the connection setup. |
---|
5 | */ |
---|
6 | |
---|
7 | #ifndef _HANDSHAKE |
---|
8 | #define _HANDSHAKE |
---|
9 | |
---|
10 | #include "base_object.h" |
---|
11 | #include "synchronizeable.h" |
---|
12 | |
---|
13 | //!< a struct to save the handshakes to |
---|
14 | struct HandshakeState |
---|
15 | { |
---|
16 | int orxId; //!< orxonox id |
---|
17 | int version; //!< network protocol version |
---|
18 | |
---|
19 | int networkManagerId; //!< unique id of the network manager |
---|
20 | int messageManagerId; //!< unique id of the message manager |
---|
21 | int hostId; //!< host id |
---|
22 | int nodeType; //!< type of the network node |
---|
23 | |
---|
24 | int completed; //!< true if completed |
---|
25 | int canDel; //!< true if marked for deletion |
---|
26 | |
---|
27 | int error; //!< error number |
---|
28 | |
---|
29 | std::string errorString; //!< error string |
---|
30 | |
---|
31 | //additional data |
---|
32 | std::string preferedNickName; //!< prefered nick name |
---|
33 | |
---|
34 | int redirectProxy; //!< true if the client should reconnect to a proxy server (either 1 or 2 ) |
---|
35 | IPaddress proxy1; //!< ip address of the first proxy (0.0.0.0 of not available) |
---|
36 | IPaddress proxy2; //!< ip address of the second proxy (0.0.0.0 of not available) |
---|
37 | }; |
---|
38 | |
---|
39 | |
---|
40 | //!< the handshake itself with some interface functions |
---|
41 | class Handshake : public Synchronizeable |
---|
42 | { |
---|
43 | |
---|
44 | public: |
---|
45 | Handshake( int nodeType, int clientId = 0, int networkGameManagerId = 0, int messageManagerId = 0 ); |
---|
46 | |
---|
47 | |
---|
48 | /* functions indicating states of the handshake */ |
---|
49 | /** @returns true if the handshake is completed */ |
---|
50 | inline bool completed(){ return localState.completed != 0 && remoteState.completed != 0; } |
---|
51 | /** @returns true if no error has occured until now */ |
---|
52 | inline bool ok(){ return localState.error == 0 && remoteState.error == 0; } |
---|
53 | /** stops the handshake and reject the other side with @param reason: string describing the reason */ |
---|
54 | inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; } |
---|
55 | /** @returns true if the handshake is finished and the instances can be deleted */ |
---|
56 | inline bool canDel(){ return localState.canDel == 1 && remoteState.canDel == 1; } |
---|
57 | /** @returns true if the local state can be removed*/ |
---|
58 | inline bool allowDel(){ return localState.canDel == 1; } |
---|
59 | /** marks the handshake to be deleted */ |
---|
60 | inline void del(){ localState.canDel = 1; } |
---|
61 | |
---|
62 | |
---|
63 | /* the actual informations exchanged in the handshake */ |
---|
64 | /** @returns the host id of the remote host */ |
---|
65 | inline int getHostId(){ return remoteState.hostId; } |
---|
66 | /** @returns the unique id of the network game manager*/ |
---|
67 | inline int getNetworkGameManagerId(){ return remoteState.networkManagerId; } |
---|
68 | /** @returns the unique id of the message manager */ |
---|
69 | inline int getMessageManagerId(){ return remoteState.messageManagerId; } |
---|
70 | /** @returns the node type of the remote host */ |
---|
71 | inline int getRemoteNodeType() { return this->remoteState.nodeType; } |
---|
72 | |
---|
73 | /** sets @param nick the prefereded nick name */ |
---|
74 | inline void setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; } |
---|
75 | /** @returns the prefered nick name */ |
---|
76 | inline std::string getPreferedNickName(){ return remoteState.preferedNickName; } |
---|
77 | |
---|
78 | /** @returns if true the local client should reconnect to a proxy server from the proxy server list */ |
---|
79 | inline bool redirect() { return this->localState.redirectProxy;} |
---|
80 | /** @param flag: indicating if the client should be redirected */ |
---|
81 | inline void setRedirect(bool flag) { this->remoteState.redirectProxy = flag; } |
---|
82 | |
---|
83 | /** @param address: the address of the proxy server 1 if any */ |
---|
84 | inline void setProxy1Address(IPaddress address) { this->localState.proxy1 = address; } |
---|
85 | /** @returns the address of the proxy server 1 if any */ |
---|
86 | inline IPaddress getProxy1Address() { return this->localState.proxy1; } |
---|
87 | /** @param address: the address of the proxy server 2 if any */ |
---|
88 | inline void setProxy2Address(IPaddress address) { this->localState.proxy2 = address; } |
---|
89 | /** @returns the address of the proxy server 2 if any */ |
---|
90 | inline IPaddress getProxy2Address() { return this->localState.proxy2; } |
---|
91 | |
---|
92 | |
---|
93 | /* variable handler function */ |
---|
94 | virtual void varChangeHandler( std::list<int> & id ); |
---|
95 | |
---|
96 | |
---|
97 | private: |
---|
98 | HandshakeState localState; //!< the local handshake state |
---|
99 | HandshakeState remoteState; //!< the remote handshake state |
---|
100 | |
---|
101 | int orxId_handler; //!< orxonox id handler |
---|
102 | int version_handler; //!< orxonox version id handler |
---|
103 | int netManId_handler; //!< network manager handler |
---|
104 | int msgManId_handler; //!< message manager handler |
---|
105 | int hostId_handler; //!< host id handler |
---|
106 | int nodeTypeHandler; //!< node type handler |
---|
107 | |
---|
108 | int completed_handler; //!< handshake completion handler |
---|
109 | int error_handler; //!< handshake error handler |
---|
110 | int errorString_handler; //!< handshake error string handler |
---|
111 | int candel_id; //!< handshake deletion handler |
---|
112 | int nodeType; //!, the type of the network node |
---|
113 | |
---|
114 | }; |
---|
115 | |
---|
116 | |
---|
117 | #endif |
---|