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