author | Tero Marttila <terom@fixme.fi> |
Tue, 20 Jan 2009 23:30:18 +0200 | |
changeset 408 | e6cfc44266af |
parent 400 | d64bf28c4340 |
child 431 | c6d7272a164b |
permissions | -rw-r--r-- |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
1 |
#ifndef NETWORKSERVER_HH |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
2 |
#define NETWORKSERVER_HH |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
3 |
|
400
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
381
diff
changeset
|
4 |
/** |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
381
diff
changeset
|
5 |
* @file |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
381
diff
changeset
|
6 |
* |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
381
diff
changeset
|
7 |
* Game server implementation |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
381
diff
changeset
|
8 |
*/ |
d64bf28c4340
more documentation tweaking, all Network/ files now have a @file comment. Fix Platform.h -> Platform.hh, and Buffer.hh + Packet.cc
Tero Marttila <terom@fixme.fi>
parents:
381
diff
changeset
|
9 |
|
186 | 10 |
#include "../GameState.hh" |
11 |
#include "Session.hh" |
|
12 |
#include "Object.hh" |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
13 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
14 |
#include <list> |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
15 |
#include <map> |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
16 |
#include <ClanLib/core.h> |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
17 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
18 |
// forward-declare |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
19 |
class NetworkServerPlayer; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
20 |
|
290 | 21 |
/** |
22 |
* Our game's NetworkServer... this has the GameState, NetworkSession, etc |
|
23 |
*/ |
|
187 | 24 |
class NetworkServer { |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
25 |
friend class NetworkServerObject; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
26 |
friend class NetworkServerPlayer; |
223 | 27 |
friend class NetworkServerProjectile; |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
28 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
29 |
protected: |
290 | 30 |
/** |
31 |
* The GameState |
|
32 |
*/ |
|
187 | 33 |
GameState &state; |
34 |
CL_SlotContainer slots; |
|
290 | 35 |
|
36 |
/** |
|
37 |
* The server-mode NetworkSession |
|
38 |
*/ |
|
39 |
NetworkSession netsession; |
|
187 | 40 |
|
290 | 41 |
/** |
42 |
* The NetworkObject_ServerController that we use |
|
43 |
*/ |
|
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
44 |
NetworkObject_ServerController controller; |
290 | 45 |
|
46 |
/** |
|
47 |
* A list of NetworkServerPlayer's, used when a new player connects to send it information about existing |
|
48 |
* NetworkServerPlayer objects |
|
49 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
50 |
std::list<NetworkServerPlayer *> players; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
51 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
52 |
public: |
290 | 53 |
/** |
54 |
* Construct a NetworkServer, using the given GameState and listening on the given address |
|
55 |
*/ |
|
381
9b35bc329d23
separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
terom
parents:
330
diff
changeset
|
56 |
NetworkServer (GameState &state, const NetworkEndpoint &listen_addr); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
57 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
58 |
protected: |
290 | 59 |
/** |
60 |
* Called by NetworkServerPlayer when it disconnects, this removes it from our list |
|
61 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
62 |
void handle_disconnect (NetworkServerPlayer *player); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
63 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
64 |
private: |
290 | 65 |
/** |
66 |
* Our NetworkSession::sig_node_connected handler, this creates a new NetworkServerPlayer and adds it to |
|
67 |
* our list of players |
|
68 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
69 |
void on_node_connected (NetworkNode *node); |
408
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
70 |
|
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
71 |
/** |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
72 |
* Called from on_node_connected to send the initial Terrain data using the NETCHAN_TERRAIN_ARRAY channel to |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
73 |
* the given node. |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
74 |
*/ |
e6cfc44266af
reorganize Terrain/PhysicsWorld/GameState/Engine to use NetworkClientConnect, and hence handle the connection process asynchronously, and finally properly implement receiving the terrain data from the server
Tero Marttila <terom@fixme.fi>
parents:
400
diff
changeset
|
75 |
void send_terrain_data (NetworkNode *node); |
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
76 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
77 |
|
290 | 78 |
/** |
79 |
* Our base NetworkObject_Server class, that also holds the NetworkServer reference and a CL_SlotContainer for |
|
80 |
* conveniance. |
|
81 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
82 |
class NetworkServerObject : public NetworkObject_Server { |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
83 |
protected: |
290 | 84 |
/** |
85 |
* Our NetworkServer |
|
86 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
87 |
NetworkServer &server; |
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
88 |
CL_SlotContainer slots; |
290 | 89 |
|
90 |
/** |
|
91 |
* Constructs this NetworkServerObject, passing the server's controller to the NetworkObject_Server constructor |
|
92 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
93 |
NetworkServerObject (NetworkServer &server); |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
94 |
}; |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
95 |
|
290 | 96 |
/** |
97 |
* A remote player on this server, this is both a LocalPlayer and a NetworkServerObject |
|
98 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
99 |
class NetworkServerPlayer : public LocalPlayer, public NetworkServerObject { |
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
100 |
protected: |
290 | 101 |
/** |
102 |
* The remote node that represents this actual player |
|
103 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
104 |
NetworkNode *node; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
105 |
|
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
106 |
public: |
290 | 107 |
/** |
108 |
* Construct this using the given server (for NetworkServerObject) and node (for node). |
|
109 |
* |
|
110 |
* We send the initial NETMSG_SERVER_HELLO to the client, then a set of NETMSG_PLAYER_INFOs |
|
111 |
* for all the other players, a NETMSG_PLAYER_JOIN to all the other clients, and then calls |
|
112 |
* send_terrain_data to sync the initial terrain. |
|
113 |
* |
|
114 |
* @see NetworkServerObject |
|
115 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
116 |
NetworkServerPlayer (NetworkServer &server, NetworkNode *node); |
239
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
117 |
|
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
118 |
protected: |
290 | 119 |
// @{ |
120 |
/** |
|
121 |
* These methods are overriden from Player to replicate events to our clients |
|
122 |
*/ |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
123 |
virtual void handleDig (Vector position, float radius); |
276
87434abc1ba1
ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents:
274
diff
changeset
|
124 |
virtual void handleFireWeapon (Weapon *weapon, Vector position, Vector velocity); |
239
550397d9d479
implement network weapon changes and fix weapon firing
terom
parents:
224
diff
changeset
|
125 |
virtual void handleChangeWeapon (unsigned int weaponIndex); |
241 | 126 |
virtual void handleRopeState (RopeState state); |
127 |
virtual void handleRopeLength (float length); |
|
302 | 128 |
|
129 |
virtual void spawn (Vector position); |
|
130 |
virtual void die (bool start_timer = true); |
|
290 | 131 |
// @} |
132 |
// |
|
133 |
||
134 |
private: |
|
135 |
/** |
|
136 |
* Our NetworkNode::sig_disconnected handler. This calls NetworkServer::handle_disconnect, sends a |
|
137 |
* NETMSG_PLAYER_QUIT message to all remaining clients, and destroys this player. |
|
138 |
*/ |
|
139 |
void on_disconnected (void); |
|
200
2dbf40661580
better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents:
187
diff
changeset
|
140 |
|
290 | 141 |
/* |
142 |
* Our NETMSG_PLAYER_INPUT handler. This calls our superclass LocalPlayer::handleInput, which may then call |
|
143 |
* the various handle* methods. After this, we call send_position_update |
|
144 |
*/ |
|
223 | 145 |
void on_input (NetworkNode *node, NetworkPacketInput &pkt); |
203
3ec7ab40755f
send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents:
200
diff
changeset
|
146 |
|
290 | 147 |
/** |
148 |
* Called from on_input to broadcast an unreliable position update with this player's physics state |
|
149 |
*/ |
|
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
150 |
void send_position_update (void); |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
151 |
}; |
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
152 |
|
290 | 153 |
/** |
154 |
* A Projectile, replicated across the network. |
|
155 |
* |
|
156 |
* These are created by NetworkServerPlayer::handleFireWeapon |
|
157 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
158 |
class NetworkServerProjectile : public Projectile, public NetworkServerObject { |
223 | 159 |
public: |
290 | 160 |
/** |
161 |
* Call the Projectile construtor, and then send NETMSG_PROJECTILE_PLAYER_FIRED |
|
162 |
* |
|
163 |
* @param server the NetworkServer |
|
164 |
* @param player the NetworkServerPlayer that fired the weapon |
|
165 |
* @param position the Projectile's initial position |
|
166 |
* @param velocity the Projectile's initial velocity |
|
167 |
* @param weapon the Player's Weapon that was fired |
|
168 |
*/ |
|
274
c35307e8645c
add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents:
263
diff
changeset
|
169 |
NetworkServerProjectile (NetworkServer &server, NetworkServerPlayer *player, Vector position, Vector velocity, Weapon *weapon); |
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
170 |
|
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
171 |
protected: |
290 | 172 |
/** |
173 |
* Overriden from Projectile to send a NETMSG_PROJECTILE_DESTROY with the given position and flags |
|
174 |
* |
|
175 |
* @param position the Projectile's final position, where the ground gets removed |
|
176 |
* @param removeGround controls the NETWORK_PROJECTILE_REMOVE_GROUND flag |
|
177 |
*/ |
|
224
e6faefba2ec1
fixed logger, and network projectiles should work reasonably well now
terom
parents:
223
diff
changeset
|
178 |
virtual void onDestroy (Vector position, bool removeGround); |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
290
diff
changeset
|
179 |
|
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
290
diff
changeset
|
180 |
/** |
330 | 181 |
* Overriden from Projectile to send a NETMSG_PROJECTILE_HIT_PLAYER with the given player |
296
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
290
diff
changeset
|
182 |
* |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
290
diff
changeset
|
183 |
* @param player the NetworkServerPlayer that got hit |
4d3ebaa29430
add separate Types.hh, and fix projectile-worm collisions on network
terom
parents:
290
diff
changeset
|
184 |
*/ |
330 | 185 |
virtual void onHitPlayer (Player *player_ptr); |
223 | 186 |
}; |
187 |
||
185
25becd2cb026
that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff
changeset
|
188 |
#endif |