src/Network/Client.cc
author Tero Marttila <terom@fixme.fi>
Tue, 27 Jan 2009 00:02:34 +0200
changeset 434 a8ba81432ddd
parent 432 82b0f4e55a13
permissions -rw-r--r--
move write_object to NetworkMessage, fix player sync, and implement projectile sync
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     1
186
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
     2
#include "Client.hh"
187
f41f894213ca restructure network code a bit
terom
parents: 186
diff changeset
     3
#include "Protocol.hh"
417
c503e0c6a740 support for building without Network/Graphics, although the disable-graphics case is kind of hackish still
Tero Marttila <terom@fixme.fi>
parents: 408
diff changeset
     4
#include "../Config.hh"
186
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
     5
#include "../Engine.hh"
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
     6
#include "../Logger.hh"
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     7
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 420
diff changeset
     8
// XXX: move
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 420
diff changeset
     9
#include "Message.hh"
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 420
diff changeset
    10
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    11
#include <cassert>
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    12
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: 406
diff changeset
    13
/*
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: 406
diff changeset
    14
 * NetworkClientConnect
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: 406
diff changeset
    15
 */
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: 406
diff changeset
    16
NetworkClientConnect::NetworkClientConnect (Engine &engine, const NetworkEndpoint &connect_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: 406
diff changeset
    17
    engine(engine), netsession(NETWORK_MAGIC_ID)
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
    18
{
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
    19
    Engine::log(INFO, "net.client") << "Connecting to server: " << connect_to;
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
    20
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: 406
diff changeset
    21
    // connect NetworkSession to get server node (this is still blocking)
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: 406
diff changeset
    22
    server = netsession.connect(connect_to);
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
    23
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
    24
    Engine::log(INFO, "net.client") << "Connected, receiving game data";
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: 406
diff changeset
    25
    
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    26
    // connect slots
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: 406
diff changeset
    27
    slots.connect(netsession.sig_chan_message(NETCHAN_TERRAIN_ARRAY), this, &NetworkClientConnect::on_terrain_array);
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: 406
diff changeset
    28
    slots.connect(server->sig_disconnected(), this, &NetworkClientConnect::on_disconnected);
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: 406
diff changeset
    29
    
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: 406
diff changeset
    30
    // then we must wait for the terrain data
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    31
}
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: 406
diff changeset
    32
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: 406
diff changeset
    33
void NetworkClientConnect::on_disconnected (void) {
332
78657bf06302 handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents: 330
diff changeset
    34
    Engine::log(ERROR, "client.on_disconnect") << "Disconnected from server";
78657bf06302 handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents: 330
diff changeset
    35
    engine.stop();
78657bf06302 handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents: 330
diff changeset
    36
}
78657bf06302 handle NetworkClient server-disconnect by logging an error and stopping the engine
terom
parents: 330
diff changeset
    37
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: 406
diff changeset
    38
void NetworkClientConnect::on_terrain_array (NetworkPacketInput &pkt, NetworkNode *node) {
203
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    39
    // ignore if not from server
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    40
    if (node != server)
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    41
        return;
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: 406
diff changeset
    42
    
203
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    43
    // read map width/height
282
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 277
diff changeset
    44
    PixelDimension map_w = pkt.read_uint32();
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 277
diff changeset
    45
    PixelDimension map_h = pkt.read_uint32();
203
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    46
387
294ce7ae8140 dirty implementation of compressed terrain array data
terom
parents: 381
diff changeset
    47
    // the terrain byte array
294ce7ae8140 dirty implementation of compressed terrain array data
terom
parents: 381
diff changeset
    48
    size_t terrain_size = map_w * map_h;
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: 406
diff changeset
    49
    TerrainPixel *terrain_buf = new TerrainPixel[map_w * map_h];
391
59c2499fe7bb add compressed read/write NetworkPacket API and move zlib stuff out of NetworkServer/Client
Tero Marttila <terom@fixme.fi>
parents: 387
diff changeset
    50
59c2499fe7bb add compressed read/write NetworkPacket API and move zlib stuff out of NetworkServer/Client
Tero Marttila <terom@fixme.fi>
parents: 387
diff changeset
    51
    // read uncompressed terrain data
59c2499fe7bb add compressed read/write NetworkPacket API and move zlib stuff out of NetworkServer/Client
Tero Marttila <terom@fixme.fi>
parents: 387
diff changeset
    52
    size_t inflate_size = pkt.read_uncompressed(terrain_buf, terrain_size);
387
294ce7ae8140 dirty implementation of compressed terrain array data
terom
parents: 381
diff changeset
    53
    
294ce7ae8140 dirty implementation of compressed terrain array data
terom
parents: 381
diff changeset
    54
    // invalid data?
294ce7ae8140 dirty implementation of compressed terrain array data
terom
parents: 381
diff changeset
    55
    if (inflate_size != terrain_size)
294ce7ae8140 dirty implementation of compressed terrain array data
terom
parents: 381
diff changeset
    56
        throw Error("Corrupt terrain data");
294ce7ae8140 dirty implementation of compressed terrain array data
terom
parents: 381
diff changeset
    57
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: 406
diff changeset
    58
    // create the terrain object that we then use, and hand over terrain_buf to it
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: 406
diff changeset
    59
    Terrain *terrain = new Terrain(map_w, map_h, terrain_buf);
203
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    60
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: 406
diff changeset
    61
    // execute connectDone
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: 406
diff changeset
    62
    connectDone(terrain);
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: 406
diff changeset
    63
}
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: 406
diff changeset
    64
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: 406
diff changeset
    65
void NetworkClientConnect::connectDone (Terrain *terrain) {
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: 406
diff changeset
    66
    // pass Terrain to engine to create game
419
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
    67
    GameState &gs = engine.onNetworkClientConnected(terrain);
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: 406
diff changeset
    68
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
    69
    Engine::log(INFO, "net.client") << "Got game data, creating player";
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
    70
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: 406
diff changeset
    71
    // create our new NetworkClient object
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 420
diff changeset
    72
    client = new NetworkClient(engine, gs, netsession, *server);
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: 406
diff changeset
    73
}
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: 406
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: 406
diff changeset
    75
/*
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: 406
diff changeset
    76
 * NetworkClient
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: 406
diff changeset
    77
 */
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 420
diff changeset
    78
NetworkClient::NetworkClient (Engine &engine, GameState &state, NetworkSession &netsession, NetworkNode &server) : 
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: 406
diff changeset
    79
    engine(engine), state(state), netsession(netsession), server(server),
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: 406
diff changeset
    80
    controller(*this)
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: 406
diff changeset
    81
{
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: 406
diff changeset
    82
203
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    83
}
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    84
        
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    85
void NetworkClient::player_quit (NetworkClientRemotePlayer *player) {
294
fd58e7d01bec finish network documentation
terom
parents: 282
diff changeset
    86
    (void) player;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    87
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    88
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    89
/*
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
    90
 * NetworkClientController
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
    91
 */ 
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
    92
NetworkClientController::NetworkClientController (NetworkClient &client) :
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
    93
    NetworkObject_ClientController(client.netsession, NETCHAN_CORE, client.server), client(client)
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
    94
{
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
    95
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
    96
}
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
    97
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
    98
void NetworkClientController::handle_create (NetworkObjectID obj_id, NetworkMessageID msg_id, NetworkPacketInput &pkt, NetworkNode *node) {
282
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 277
diff changeset
    99
    // XXX: should be server
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 277
diff changeset
   100
    (void) node;
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 277
diff changeset
   101
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   102
    switch (msg_id) {
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   103
        case NETMSG_SERVER_HELLO:
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   104
            on_server_hello(obj_id, pkt);
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   105
            break;
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   106
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   107
        case NETMSG_PLAYER_INFO:
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   108
            on_player_info(obj_id, pkt);
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   109
            break;
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   110
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   111
        case NETMSG_PLAYER_JOIN:
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   112
            on_player_join(obj_id, pkt);
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   113
            break;
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 420
diff changeset
   114
        
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 420
diff changeset
   115
        case NETMSG_PROJECTILE_INFO:
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   116
        case NETMSG_PROJECTILE_PLAYER_FIRED:
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 420
diff changeset
   117
            on_projectile_create(obj_id, pkt);
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   118
            break;
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   119
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   120
        default:
434
a8ba81432ddd move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents: 432
diff changeset
   121
            Engine::log(WARN, "client.handle_create") 
a8ba81432ddd move write_object to NetworkMessage, fix player sync, and implement projectile sync
Tero Marttila <terom@fixme.fi>
parents: 432
diff changeset
   122
                << "Unknown object create message: obj_id=" << obj_id << ", msg_id=" << std::hex << msg_id;
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   123
    }
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   124
}
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   125
        
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   126
void NetworkClientController::on_server_hello (NetworkObjectID obj_id, NetworkPacketInput &pkt) {
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   127
    // read the packet
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   128
    Vector position = pkt.read_vector();
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   129
    
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   130
    Engine::log(DEBUG, "client.on_server_hello") << this << ": pos=" << position;
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   131
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   132
    // create the LocalPlayer object
419
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   133
    NetworkClientLocalPlayer *player = new NetworkClientLocalPlayer(client, obj_id, position);
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   134
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   135
    // pass it on to engine
9cd4e54693b6 fix Engine <-> NetworkClient interaction
Tero Marttila <terom@fixme.fi>
parents: 417
diff changeset
   136
    client.engine.onNetworkClientPlayer(player);
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   137
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   138
    Engine::log(INFO, "net.client") << "Joined server: " << player;
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   139
}
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   140
        
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   141
void NetworkClientController::on_player_info (NetworkObjectID obj_id, NetworkPacketInput &pkt) {
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   142
    // read the packet
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   143
    Vector position = pkt.read_vector();
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   144
    
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   145
    Engine::log(DEBUG, "client.on_player_info") << this << ": pos=" << position;
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   146
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   147
    // create the LocalPlayer object
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   148
    new NetworkClientRemotePlayer(client, obj_id, position);
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   149
}
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   150
        
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   151
void NetworkClientController::on_player_join (NetworkObjectID obj_id, NetworkPacketInput &pkt) {
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   152
    // read the packet
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   153
    Vector position = pkt.read_vector();
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   154
    
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   155
    Engine::log(DEBUG, "client.on_player_join") << this << ": pos=" << position;
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   156
    
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   157
    // create the RemotePlayer object
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   158
    NetworkClientRemotePlayer *player = new NetworkClientRemotePlayer(client, obj_id, position);
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   159
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   160
    Engine::log(INFO, "net.client") << "Player joined: " << player;
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   161
}
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   162
        
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 420
diff changeset
   163
void NetworkClientController::on_projectile_create (NetworkObjectID obj_id, NetworkPacketInput &pkt) {
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   164
    // read the packet
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   165
    NetworkObject *player_obj = client.controller.read_object(pkt);
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   166
    Vector position = pkt.read_vector();
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   167
    Vector velocity = pkt.read_vector();
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   168
    WeaponID weapon_id = pkt.read_uint8();
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   169
    
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   170
    NetworkClientPlayerBase *player;
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   171
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   172
    // ignore for invalid players
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   173
    if ((player = dynamic_cast<NetworkClientPlayerBase*>(player_obj)) == NULL) {
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   174
        Engine::log(ERROR, "client.on_projectile_player_fired") << this << ": Unknown player object";
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   175
        return;
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   176
    }
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   177
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   178
    Weapon *weapon;
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   179
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   180
    // try and get the weapon
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   181
    if ((weapon = player->getWeapon(weapon_id)) == NULL) {
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   182
        Engine::log(ERROR, "client.on_projectile_player_fired") << this << ": Unknown weapon id: player=" << player << ", weapon_id=" << weapon_id;
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   183
    }
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   184
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   185
    Engine::log(DEBUG, "client.on_projectile_create") << this << ": player=" << player << ", pos=" << position << ", velocity=" << velocity << ", weapon=" << weapon;
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   186
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   187
    // create the NetworkClientPorjectile object
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   188
    new NetworkClientProjectile(client, obj_id, player, position, velocity, weapon);
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   189
}
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   190
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   191
/*
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   192
 * NetworkClientObject
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   193
 */
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   194
NetworkClientObject::NetworkClientObject (NetworkClient &client, NetworkObjectID obj_id) :
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   195
    NetworkObject_Client(client.controller, obj_id), client(client)
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   196
{
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   197
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   198
}
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   199
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   200
/*
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   201
 * NetworkClientPlayerBase
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   202
 */
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   203
NetworkClientPlayerBase::NetworkClientPlayerBase (NetworkClient &client, NetworkObjectID obj_id, Vector position) :
282
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 277
diff changeset
   204
    Player(client.state, position, true),
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 277
diff changeset
   205
    NetworkClientObject(client, obj_id)
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   206
{
302
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   207
    slots.connect(sig_message(NETMSG_PLAYER_POSITION),          this,   &NetworkClientPlayerBase::on_position           );
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   208
    slots.connect(sig_message(NETMSG_PLAYER_DIG),               this,   &NetworkClientPlayerBase::on_dig                );
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   209
    slots.connect(sig_message(NETMSG_PLAYER_WEAPON_CHANGE),     this,   &NetworkClientPlayerBase::on_weapon_change      );
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   210
    slots.connect(sig_message(NETMSG_PLAYER_ROPE_THROW),        this,   &NetworkClientPlayerBase::on_rope_throw         );
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   211
    slots.connect(sig_message(NETMSG_PLAYER_ROPE_FIXED),        this,   &NetworkClientPlayerBase::on_rope_fixed         );
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   212
    slots.connect(sig_message(NETMSG_PLAYER_ROPE_RELEASED),     this,   &NetworkClientPlayerBase::on_rope_released      );
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   213
    slots.connect(sig_message(NETMSG_PLAYER_ROPE_LENGTH),       this,   &NetworkClientPlayerBase::on_rope_length        );
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   214
    slots.connect(sig_message(NETMSG_PLAYER_SPAWN),             this,   &NetworkClientPlayerBase::on_spawn              );
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   215
    slots.connect(sig_message(NETMSG_PLAYER_DIE),               this,   &NetworkClientPlayerBase::on_die                );
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   216
}
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   217
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   218
void NetworkClientPlayerBase::spawn (Vector position) {
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   219
    (void) position;
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   220
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   221
    throw Error("NetworkClientPlayerBase::spawn called");
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   222
}
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   223
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   224
void NetworkClientPlayerBase::respawn (TimeMS dt) {
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   225
    (void) dt;
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   226
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   227
    throw Error("NetworkClientPlayerBase::respawn called");
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   228
}
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   229
303
36a502a0023f just ignore NetworkClientPlayerBase::die
terom
parents: 302
diff changeset
   230
void NetworkClientPlayerBase::die (bool start_timer) {
36a502a0023f just ignore NetworkClientPlayerBase::die
terom
parents: 302
diff changeset
   231
    (void) start_timer;
36a502a0023f just ignore NetworkClientPlayerBase::die
terom
parents: 302
diff changeset
   232
    
36a502a0023f just ignore NetworkClientPlayerBase::die
terom
parents: 302
diff changeset
   233
    // ignore :>
36a502a0023f just ignore NetworkClientPlayerBase::die
terom
parents: 302
diff changeset
   234
}
36a502a0023f just ignore NetworkClientPlayerBase::die
terom
parents: 302
diff changeset
   235
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   236
void NetworkClientPlayerBase::on_position (NetworkPacketInput &pkt) {
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   237
    Vector position = pkt.read_vector();
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   238
    Vector velocity = pkt.read_vector();
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   239
    int flags = pkt.read_uint8();
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   240
    float aim = pkt.read_float32();
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   241
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   242
//    Engine::log(DEBUG, "client_player.on_position") << "obj=" << obj << ", position=" << position << ", velocity=" << velocity << ", aim=" << aim << ", [" << flags << "]";
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   243
    
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   244
    // just update... 
264
215de3d4de60 change facingRight from a bool to an
terom
parents: 263
diff changeset
   245
    updatePhysics(position, velocity, 
215de3d4de60 change facingRight from a bool to an
terom
parents: 263
diff changeset
   246
            flags & NETWORK_PHYSICS_INAIR, 
215de3d4de60 change facingRight from a bool to an
terom
parents: 263
diff changeset
   247
            flags & NETWORK_PHYSICS_FACE_RIGHT ? FACING_RIGHT : FACING_LEFT, 
215de3d4de60 change facingRight from a bool to an
terom
parents: 263
diff changeset
   248
            aim
215de3d4de60 change facingRight from a bool to an
terom
parents: 263
diff changeset
   249
    );
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   250
}
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   251
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   252
void NetworkClientPlayerBase::on_dig (NetworkPacketInput &pkt) {
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   253
    Vector position = pkt.read_vector();
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   254
    float radius = pkt.read_float32();
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   255
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   256
    Engine::log(DEBUG, "client_player.on_dig") << this << ": position=" << position << ", radius=" << radius;
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   257
    
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   258
    // just update... 
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 203
diff changeset
   259
    handleDig(position, radius);
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   260
}
239
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   261
        
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   262
void NetworkClientPlayerBase::on_weapon_change (NetworkPacketInput &pkt) {
239
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   263
    uint8_t weapon_index = pkt.read_uint8();
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   264
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   265
    Engine::log(DEBUG, "client_player.on_weapon_change") << this << ": weapon_index=" << weapon_index;
239
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   266
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   267
    handleChangeWeapon(weapon_index);
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   268
}
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   269
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   270
void NetworkClientPlayerBase::on_rope_throw (NetworkPacketInput &pkt) {
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   271
    Vector position = pkt.read_vector();
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   272
    Vector velocity = pkt.read_vector();
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   273
    float length = pkt.read_float32();
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   274
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   275
    Engine::log(DEBUG, "client_player.on_rope_throw") << this << ": position=" << position << ", velocity=" << velocity << ", length=" << length;
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   276
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   277
    rope.updateState(ROPE_FLYING, position, velocity, length, NULL);
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   278
}
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   279
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   280
void NetworkClientPlayerBase::on_rope_fixed (NetworkPacketInput &pkt) {
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   281
    Vector position = pkt.read_vector();
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   282
    float length = pkt.read_float32();
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   283
    NetworkObject *player_obj = controller.read_object(pkt);
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   284
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   285
    NetworkClientPlayerBase *player = NULL;
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   286
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   287
    if (player_obj != NULL && (player = dynamic_cast<NetworkClientPlayerBase*>(player_obj)) == NULL) {
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   288
        Engine::log(ERROR, "client.on_rope_fixed") << this << ": Unknown player object";
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   289
        return;
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   290
    }
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   291
    
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   292
    Engine::log(DEBUG, "client_player.on_rope_fixed") << this << ": position=" << position << ", length=" << length 
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   293
        << ", player=" << player;
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   294
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   295
    rope.updateState(ROPE_FIXED, position, Vector(0, 0), length, player);
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   296
}
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   297
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   298
void NetworkClientPlayerBase::on_rope_released (NetworkPacketInput &pkt) {
282
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 277
diff changeset
   299
    (void) pkt;
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 277
diff changeset
   300
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   301
    Engine::log(DEBUG, "client_player.on_rope_released") << this;
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   302
    
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   303
    // use rope.getPosition() instead of e.g. Vector(0, 0) because it will collide there...
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   304
    rope.updateState(ROPE_FOLDED, rope.getPosition(), Vector(0, 0), 0, NULL);
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   305
}
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   306
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   307
void NetworkClientPlayerBase::on_rope_length (NetworkPacketInput &pkt) {
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   308
    float length = pkt.read_float32();
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   309
    
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   310
    Engine::log(DEBUG, "client_player.on_rope_length") << this << ": length=" << length;
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   311
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   312
    rope.updateLength(length);
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   313
}
302
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   314
        
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   315
void NetworkClientPlayerBase::on_spawn (NetworkPacketInput &pkt) {
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   316
    // read packet
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   317
    Vector position = pkt.read_vector();
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   318
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   319
    Engine::log(DEBUG, "client_player.on_spawn") << this << ": position=" << position;
302
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   320
    
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   321
    // super
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   322
    Player::spawn(position);
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   323
}
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   324
        
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   325
void NetworkClientPlayerBase::on_die (NetworkPacketInput &pkt) {
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   326
    (void) pkt;
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   327
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   328
    Engine::log(DEBUG, "client_player.on_die") << this;
302
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   329
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   330
    // super, but don't start the respawn_timer
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   331
    Player::die(false);
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   332
}
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   333
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   334
/*
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   335
 * NetworkClientLocalPlayer
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   336
 */
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   337
NetworkClientLocalPlayer::NetworkClientLocalPlayer (NetworkClient &client, NetworkObjectID obj_id, Vector position) :
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   338
    Player(client.state, position, true), NetworkClientPlayerBase(client, obj_id, position) 
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   339
{
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   340
    // set ourselves as the local player
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   341
    state.setLocalPlayer(this);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   342
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   343
        
277
40f4a03917e2 fix NetworkClient handleInput
terom
parents: 276
diff changeset
   344
void NetworkClientLocalPlayer::handleInput (PlayerInput input, TimeMS dt) {
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 420
diff changeset
   345
    NetworkMessage msg (*this, NETMSG_CLIENT_INPUT);
277
40f4a03917e2 fix NetworkClient handleInput
terom
parents: 276
diff changeset
   346
334
0cf3f2be51eb transmit handleInput dt
terom
parents: 332
diff changeset
   347
    // write packet
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 420
diff changeset
   348
    msg.write_uint16(input);
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 420
diff changeset
   349
    msg.write_uint32(dt);
334
0cf3f2be51eb transmit handleInput dt
terom
parents: 332
diff changeset
   350
    
431
c6d7272a164b rework Network send() code to use NetworkTarget/Node/Group::send classes, add a NetworkMessage class for sending NetworkObject messages, and fix a bug whereby the server's client TCP sockets weren't nonblocking.... I wonder how this has worked before?\!
Tero Marttila <terom@fixme.fi>
parents: 420
diff changeset
   351
    // send to server
432
82b0f4e55a13 add NetworkChannelPacket class, and modify NetworkTarget::send/send_raw signature. Add hard-coded DEBUG_ENABLED define
Tero Marttila <terom@fixme.fi>
parents: 431
diff changeset
   352
    client.server.send(msg);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   353
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   354
    // do not handle locally
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   355
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   356
        
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   357
/*
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   358
 * NetworkClientRemotePlayer
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   359
 */
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   360
NetworkClientRemotePlayer::NetworkClientRemotePlayer (NetworkClient &client, NetworkObjectID obj_id, Vector position) :
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   361
    Player(client.state, position, true), NetworkClientPlayerBase(client, obj_id, position) {
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   362
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   363
    // receive messages
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   364
    slots.connect(sig_message(NETMSG_PLAYER_QUIT), this, &NetworkClientRemotePlayer::on_quit);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   365
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   366
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   367
void NetworkClientRemotePlayer::on_quit (NetworkPacketInput &pkt) {
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   368
    // pkt is empty
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   369
    (void) pkt;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   370
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   371
    Engine::log(INFO, "net.client") << "Player quit: " << this;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   372
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   373
    client.player_quit(this);
294
fd58e7d01bec finish network documentation
terom
parents: 282
diff changeset
   374
fd58e7d01bec finish network documentation
terom
parents: 282
diff changeset
   375
    // delete
fd58e7d01bec finish network documentation
terom
parents: 282
diff changeset
   376
    // XXX: leak because deleting the slot while it's being called breaks ClanLib
fd58e7d01bec finish network documentation
terom
parents: 282
diff changeset
   377
    //  delete this;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   378
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   379
294
fd58e7d01bec finish network documentation
terom
parents: 282
diff changeset
   380
/*
fd58e7d01bec finish network documentation
terom
parents: 282
diff changeset
   381
 * NetworkClientProjectile
fd58e7d01bec finish network documentation
terom
parents: 282
diff changeset
   382
 */
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   383
NetworkClientProjectile::NetworkClientProjectile (NetworkClient &client, NetworkObjectID obj_id, Player *player,
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   384
        Vector position, Vector velocity, Weapon *weapon) :
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   385
    NetworkClientObject(client, obj_id), Projectile(player, position, velocity, weapon)
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   386
{
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   387
    // hook up signals
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   388
    slots.connect(sig_message(NETMSG_PROJECTILE_DESTROY), this, &NetworkClientProjectile::on_destroy);
296
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   389
    slots.connect(sig_message(NETMSG_PROJECTILE_HIT_PLAYER), this, &NetworkClientProjectile::on_hit_player);
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   390
    
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   391
    // tell Player
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 274
diff changeset
   392
    player->weaponFired(weapon);
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   393
}
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   394
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   395
void NetworkClientProjectile::onDestroy (Vector position, bool removeGround) {
282
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 277
diff changeset
   396
    (void) position;
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 277
diff changeset
   397
    (void) removeGround;
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 277
diff changeset
   398
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   399
    // ignore :>
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   400
}
296
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   401
        
330
dcc47278e5ab fix Network Projectile::onHitPlayer
terom
parents: 328
diff changeset
   402
void NetworkClientProjectile::onHitPlayer (Player *player) {
296
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   403
    (void) player;
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   404
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   405
    // ignore :>
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   406
}
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   407
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   408
void NetworkClientProjectile::on_destroy (NetworkPacketInput &pkt) {
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   409
    Vector position = pkt.read_vector();
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   410
    uint8_t flags = pkt.read_uint8();
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   411
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   412
    Engine::log(DEBUG, "client_projectile.on_destroy") << this << ": position=" << position << ", flags=" << flags;
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   413
    
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   414
    // pass on to super
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   415
    Projectile::onDestroy(position, flags & NETWORK_PROJECTILE_REMOVE_GROUND);
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   416
}
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 264
diff changeset
   417
296
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   418
void NetworkClientProjectile::on_hit_player (NetworkPacketInput &pkt) {
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   419
    // read packet
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   420
    NetworkObject *player_obj = controller.read_object(pkt);
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   421
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   422
    NetworkClientPlayerBase *player;
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   423
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   424
    // ignore for invalid players
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   425
    if ((player = dynamic_cast<NetworkClientPlayerBase*>(player_obj)) == NULL) {
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   426
        Engine::log(ERROR, "client.on_hit_player") << this << ": Unknown player object";
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   427
        return;
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   428
    }
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   429
    
420
278020dcd9b7 clean up Server/Client log output a bit
Tero Marttila <terom@fixme.fi>
parents: 419
diff changeset
   430
    Engine::log(DEBUG, "client_projectile.hit_player") << this << ": player=" << player;
296
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   431
    
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   432
    // pass on to super
308
60f4b55d5713 Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents: 303
diff changeset
   433
    Projectile::onHitPlayer(player);
296
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   434
}
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 294
diff changeset
   435