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: christoph |
---|
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 "handshake.h" |
---|
23 | |
---|
24 | #include <cassert> |
---|
25 | |
---|
26 | Handshake::Handshake( bool server, int clientId, int networkGameManagerId ) |
---|
27 | : Synchronizeable() |
---|
28 | { |
---|
29 | /* set the class id for the base object */ |
---|
30 | this->setClassID(CL_HANDSHAKE, "Handshake"); |
---|
31 | |
---|
32 | this->setIsServer(server); |
---|
33 | this->localState.hostId = clientId; |
---|
34 | this->localState.networkManagerId = networkGameManagerId; |
---|
35 | |
---|
36 | orxId_handler = registerVarId( new SynchronizeableInt( &localState.orxId, &remoteState.orxId, "orxonoxId", PERMISSION_ALL ) ); |
---|
37 | version_handler = registerVarId( new SynchronizeableInt( &localState.version, &remoteState.version, "version", PERMISSION_ALL ) ); |
---|
38 | netManId_handler = registerVarId( new SynchronizeableInt( &localState.networkManagerId, &remoteState.networkManagerId, "networkManagerId", PERMISSION_ALL ) ); |
---|
39 | hostId_handler = registerVarId( new SynchronizeableInt( &localState.hostId, &remoteState.hostId, "hostId", PERMISSION_ALL ) ); |
---|
40 | completed_handler = registerVarId( new SynchronizeableInt( &localState.completed, &remoteState.completed, "completed", PERMISSION_ALL ) ); |
---|
41 | error_handler = registerVarId( new SynchronizeableInt( &localState.error, &remoteState.error, "error", PERMISSION_ALL ) ); |
---|
42 | errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", PERMISSION_ALL ) ); |
---|
43 | |
---|
44 | localState.completed = false; |
---|
45 | localState.error = 0; |
---|
46 | localState.errorString = ""; |
---|
47 | localState.hostId = clientId; |
---|
48 | localState.networkManagerId = networkGameManagerId; |
---|
49 | localState.orxId = _ORXONOX_ID; |
---|
50 | localState.version = _ORXONOX_VERSION; |
---|
51 | |
---|
52 | remoteState.completed = false; |
---|
53 | remoteState.error = 0; |
---|
54 | remoteState.errorString = ""; |
---|
55 | remoteState.hostId = -1; |
---|
56 | remoteState.networkManagerId = -1; |
---|
57 | remoteState.orxId = 0; |
---|
58 | remoteState.version = 0; |
---|
59 | |
---|
60 | this->setSynchronized(true); |
---|
61 | PRINTF(5)("Handshake created clientId = %d\n", clientId); |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
65 | * handler for changes in synced vars |
---|
66 | * @param id id's which have changed |
---|
67 | */ |
---|
68 | void Handshake::varChangeHandler( std::list< int > & id ) |
---|
69 | { |
---|
70 | for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ ) |
---|
71 | { |
---|
72 | if ( *it == orxId_handler ) |
---|
73 | { |
---|
74 | if ( remoteState.orxId != _ORXONOX_ID ) |
---|
75 | { |
---|
76 | localState.error = 1; |
---|
77 | localState.completed = true; |
---|
78 | localState.errorString = "Seems not to be orxonox!"; |
---|
79 | return; |
---|
80 | } |
---|
81 | else |
---|
82 | localState.completed = true; |
---|
83 | } |
---|
84 | |
---|
85 | if ( *it == version_handler ) |
---|
86 | { |
---|
87 | if ( remoteState.version != _ORXONOX_VERSION ) |
---|
88 | { |
---|
89 | localState.error = 2; |
---|
90 | localState.completed = true; |
---|
91 | localState.errorString = "Versions of server and client do not match!"; |
---|
92 | return; |
---|
93 | } |
---|
94 | else |
---|
95 | localState.completed = true; |
---|
96 | } |
---|
97 | |
---|
98 | } |
---|
99 | } |
---|
100 | |
---|