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 | #include "debug.h" |
---|
26 | |
---|
27 | Handshake::Handshake( bool server, int clientId, int networkGameManagerId, int messageManagerId ) |
---|
28 | : Synchronizeable() |
---|
29 | { |
---|
30 | /* set the class id for the base object */ |
---|
31 | this->setClassID(CL_HANDSHAKE, "Handshake"); |
---|
32 | |
---|
33 | this->setIsServer(server); |
---|
34 | |
---|
35 | // register all variable handlers |
---|
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 | msgManId_handler = registerVarId( new SynchronizeableInt( &localState.messageManagerId, &remoteState.messageManagerId, "messageManagerId", PERMISSION_ALL ) ); |
---|
40 | hostId_handler = registerVarId( new SynchronizeableInt( &localState.hostId, &remoteState.hostId, "hostId", PERMISSION_ALL ) ); |
---|
41 | completed_handler = registerVarId( new SynchronizeableInt( &localState.completed, &remoteState.completed, "completed", PERMISSION_ALL ) ); |
---|
42 | error_handler = registerVarId( new SynchronizeableInt( &localState.error, &remoteState.error, "error", PERMISSION_ALL ) ); |
---|
43 | errorString_handler = registerVarId( new SynchronizeableString( &localState.errorString, &remoteState.errorString, "errorString", PERMISSION_ALL ) ); |
---|
44 | |
---|
45 | candel_id = registerVarId( new SynchronizeableInt( &localState.canDel, &remoteState.canDel, "canDel", PERMISSION_ALL ) ); |
---|
46 | |
---|
47 | registerVar( new SynchronizeableString( &localState.preferedNickName, &remoteState.preferedNickName, "preferedNickName", PERMISSION_ALL ) ); |
---|
48 | |
---|
49 | // init the local state |
---|
50 | localState.completed = 0; |
---|
51 | localState.error = 0; |
---|
52 | localState.errorString = ""; |
---|
53 | localState.hostId = clientId; |
---|
54 | localState.networkManagerId = networkGameManagerId; |
---|
55 | this->localState.messageManagerId = messageManagerId; |
---|
56 | localState.orxId = _ORXONOX_ID; |
---|
57 | localState.version = _ORXONOX_VERSION; |
---|
58 | localState.canDel = 0; |
---|
59 | |
---|
60 | remoteState.completed = 0; |
---|
61 | remoteState.error = 0; |
---|
62 | remoteState.errorString = ""; |
---|
63 | remoteState.hostId = -1; |
---|
64 | remoteState.networkManagerId = -1; |
---|
65 | remoteState.messageManagerId = -1; |
---|
66 | remoteState.orxId = 0; |
---|
67 | remoteState.version = 0; |
---|
68 | remoteState.canDel = 0; |
---|
69 | |
---|
70 | // activate the synchronization process |
---|
71 | this->setSynchronized(true); |
---|
72 | PRINTF(0)("Handshake created clientId = %d\n", clientId); |
---|
73 | } |
---|
74 | |
---|
75 | /** |
---|
76 | * handler for changes in synced vars |
---|
77 | * @param id id's which have changed |
---|
78 | */ |
---|
79 | void Handshake::varChangeHandler( std::list< int > & id ) |
---|
80 | { |
---|
81 | for ( std::list<int>::iterator it = id.begin(); it != id.end(); it++ ) |
---|
82 | { |
---|
83 | if ( *it == orxId_handler ) |
---|
84 | { |
---|
85 | if ( remoteState.orxId != _ORXONOX_ID ) |
---|
86 | { |
---|
87 | localState.error = 1; |
---|
88 | localState.completed = 1; |
---|
89 | localState.errorString = "Seems not to be orxonox!"; |
---|
90 | continue; |
---|
91 | } |
---|
92 | |
---|
93 | } |
---|
94 | |
---|
95 | if ( *it == version_handler ) |
---|
96 | { |
---|
97 | if ( remoteState.version != _ORXONOX_VERSION ) |
---|
98 | { |
---|
99 | localState.error = 2; |
---|
100 | localState.completed = 1; |
---|
101 | localState.errorString = "Versions of server and client do not match!"; |
---|
102 | continue; |
---|
103 | } |
---|
104 | |
---|
105 | } |
---|
106 | |
---|
107 | if ( *it == candel_id ) |
---|
108 | { |
---|
109 | PRINTF(0)("handshake finished candel changed\n"); |
---|
110 | } |
---|
111 | |
---|
112 | } |
---|
113 | |
---|
114 | if ( |
---|
115 | remoteState.orxId == _ORXONOX_ID && |
---|
116 | remoteState.version == _ORXONOX_VERSION |
---|
117 | ) |
---|
118 | localState.completed = 1; |
---|
119 | } |
---|
120 | |
---|