src/Network/Server.cc
author terom
Wed, 17 Dec 2008 00:40:22 +0000
changeset 381 9b35bc329d23
parent 355 0fafdf0029c0
child 387 294ce7ae8140
permissions -rw-r--r--
separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
187
f41f894213ca restructure network code a bit
terom
parents: 186
diff changeset
     1
186
0738f2949a2b move src/Network% to src/Network/%
terom
parents: 185
diff changeset
     2
#include "Server.hh"
187
f41f894213ca restructure network code a bit
terom
parents: 186
diff changeset
     3
#include "Protocol.hh"
f41f894213ca restructure network code a bit
terom
parents: 186
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
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     8
#include <cassert>
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
     9
381
9b35bc329d23 separate sockaddr stuff out of NetworkAddress... now called NetworkEndpoint
terom
parents: 355
diff changeset
    10
NetworkServer::NetworkServer (GameState &state, const NetworkEndpoint &listen_addr) : 
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 275
diff changeset
    11
    state(state), netsession(NETWORK_MAGIC_ID), controller(netsession, NETCHAN_CORE) {
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    12
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    13
    // connect slots
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    14
    slots.connect(netsession.sig_node_connected(), this, &NetworkServer::on_node_connected);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    15
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    16
    // and then we listen
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    17
    netsession.listen(listen_addr);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    18
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    19
    Engine::log(INFO, "server") << "running, listen_addr=" << listen_addr;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    20
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    21
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    22
void NetworkServer::on_node_connected (NetworkNode *node) {
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    23
    // create the player object (it logs it)
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    24
    NetworkServerPlayer *player = new NetworkServerPlayer(*this, node);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    25
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    26
    // add to players
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    27
    players.push_back(player);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    28
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    29
        
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    30
void NetworkServer::handle_disconnect (NetworkServerPlayer *player) {
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    31
    // remove from list
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    32
    players.remove(player);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    33
}
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    34
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    35
/*
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    36
 * NetworkServerObject
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    37
 */
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    38
NetworkServerObject::NetworkServerObject (NetworkServer &server) :
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 275
diff changeset
    39
    NetworkObject_Server(server.controller), server(server)
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    40
{
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    41
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    42
}
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    43
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    44
/*
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    45
 * NetworkServerPlayer
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    46
 */
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    47
NetworkServerPlayer::NetworkServerPlayer (NetworkServer &server, NetworkNode *node) : 
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    48
    Player(server.state, Vector(PLAYER_INITIAL_X, PLAYER_INITIAL_Y), true), NetworkServerObject(server), node(node) 
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    49
{
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    50
    // log
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    51
    Engine::log(INFO, "server_player.connected") << this << ": node=" << node;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    52
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    53
    // messages
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    54
    slots.connect(node->sig_disconnected(), this, &NetworkServerPlayer::on_disconnected);
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    55
    slots.connect(this->sig_message(NETMSG_CLIENT_INPUT), this, &NetworkServerPlayer::on_input);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    56
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    57
    // the initial NETMSG_PLAYER_HELLO
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    58
    NetworkPacket hello_pkt;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    59
    hello_pkt.write_vector(position);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    60
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    61
    this->send_to(node, NETMSG_SERVER_HELLO, hello_pkt, true);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    62
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    63
    // send other player objects
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    64
    for (std::list<NetworkServerPlayer*>::iterator it = server.players.begin(); it != server.players.end(); it++) {
355
0fafdf0029c0 misc. touching up of doc and NetworkServer comments...
terom
parents: 334
diff changeset
    65
        NetworkPacket player_pkt;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    66
        NetworkServerPlayer *player = *it;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    67
        
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    68
        // player is not in players list yet
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    69
        assert(player != this);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    70
        
355
0fafdf0029c0 misc. touching up of doc and NetworkServer comments...
terom
parents: 334
diff changeset
    71
        // write packet
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    72
        player_pkt.write_vector(player->position);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    73
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    74
        player->send_to(node, NETMSG_PLAYER_INFO, player_pkt, true);
355
0fafdf0029c0 misc. touching up of doc and NetworkServer comments...
terom
parents: 334
diff changeset
    75
0fafdf0029c0 misc. touching up of doc and NetworkServer comments...
terom
parents: 334
diff changeset
    76
        // XXX: send rope info...
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    77
    }
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    78
355
0fafdf0029c0 misc. touching up of doc and NetworkServer comments...
terom
parents: 334
diff changeset
    79
    // XXX: send projectiles? Or let the client handle the events that the unknown projectiles generate?
0fafdf0029c0 misc. touching up of doc and NetworkServer comments...
terom
parents: 334
diff changeset
    80
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    81
    // broadcast NETMSG_PLAYER_JOIN to all clients except current
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    82
    this->send_all_except(NETMSG_PLAYER_JOIN, hello_pkt, node, true);
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
    // send terrain data...
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    85
    send_terrain_data();
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    86
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    87
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
    88
void NetworkServerPlayer::handleDig (Vector position, float radius) {
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
    89
    NetworkPacket pkt;
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
    90
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
    91
    pkt.write_vector(position);
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
    92
    pkt.write_float32(radius);
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
    93
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
    94
    Engine::log(INFO, "server_player.handle_dig") << "position=" << position << ", radius=" << radius;
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
    95
    
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
    96
    // tell everyone... make this reliable... 
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
    97
    this->send_all(NETMSG_PLAYER_DIG, pkt, true);
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
    98
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
    99
    // and carry out the actual dig on the server as well
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   100
    Player::handleDig(position, radius);
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   101
}
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   102
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 275
diff changeset
   103
void NetworkServerPlayer::handleFireWeapon (Weapon *weapon, Vector position, Vector velocity) {
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 275
diff changeset
   104
    Engine::log(INFO, "server_player.fire_weapon") << "weapon='" << weapon->getName() << "', position=" << position << ", velocity=" << velocity;
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   105
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   106
    // create new NetworkServerProjectile object
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
   107
    new NetworkServerProjectile(server, this, position, velocity, weapon);
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 275
diff changeset
   108
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 275
diff changeset
   109
    // as handleFireWeapon does
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 275
diff changeset
   110
    weaponFired(weapon);
239
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   111
}
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   112
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   113
void NetworkServerPlayer::handleChangeWeapon (unsigned int weaponIndex) {
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   114
    NetworkPacket pkt;
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   115
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   116
    Engine::log(INFO, "server_player.change_weapon") << "weaponIndex=" << weaponIndex;
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   117
    
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   118
    // write packet
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   119
    pkt.write_uint8(weaponIndex);
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   120
    
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   121
    // XXX: only tell the client itself?
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
   122
    send_all(NETMSG_PLAYER_WEAPON_CHANGE, pkt, true);
239
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   123
    
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   124
    // pass through
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   125
    Player::handleChangeWeapon(weaponIndex);
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   126
}
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   127
        
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   128
void NetworkServerPlayer::handleRopeState (RopeState state) {
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   129
    NetworkPacket pkt; 
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   130
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   131
    Engine::log(INFO, "server_player.rope_state") << "state=" << rope.getState() << ", position=" << rope.getPosition() << ", velocity=" << rope.getVelocity() << ", length=" << rope.getLength() << ", pivotPlayer=" << rope.getPivotPlayer();
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   132
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   133
    switch (state) {
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   134
    case ROPE_FLYING:
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   135
        pkt.write_vector(rope.getPosition());
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   136
        pkt.write_vector(rope.getVelocity());
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   137
        pkt.write_float32(rope.getLength());
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   138
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
   139
        send_all(NETMSG_PLAYER_ROPE_THROW, pkt, true);
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   140
        
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   141
        break;
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   142
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   143
    case ROPE_FIXED: {
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   144
        Player *player_base = rope.getPivotPlayer();
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   145
        NetworkServerPlayer *player = NULL;
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   146
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   147
        if (player_base != NULL && (player = dynamic_cast<NetworkServerPlayer*>(player_base)) == NULL)
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   148
            throw Error("NetworkServerPlayer::handleRopeState: rope's pivotPlayer is not a NetworkServerPlayer");
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   149
        
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   150
        pkt.write_vector(rope.getPosition());
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   151
        pkt.write_float32(rope.getLength());
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   152
        controller.write_object(pkt, player);    // may be NULL
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   153
        
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
   154
        send_all(NETMSG_PLAYER_ROPE_FIXED, pkt, true);
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   155
328
51d644c8d5a2 fix player-pivoted rope
terom
parents: 308
diff changeset
   156
    } break;
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   157
    
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   158
    case ROPE_FOLDED:
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
   159
        send_all(NETMSG_PLAYER_ROPE_RELEASED, pkt, true);
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   160
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   161
        break;
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   162
    }
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   163
}
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   164
        
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   165
void NetworkServerPlayer::handleRopeLength (float length) {
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   166
    NetworkPacket pkt;
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   167
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   168
    pkt.write_float32(length);
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   169
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
   170
    send_all(NETMSG_PLAYER_ROPE_LENGTH, pkt, true);
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   171
}
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   172
302
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   173
void NetworkServerPlayer::spawn (Vector position) {
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   174
    NetworkPacket pkt;
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   175
    
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   176
    // write packet
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   177
    pkt.write_vector(position);
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   178
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   179
    Engine::log(INFO, "server_player.spawn") << this << ": position=" << position;
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   180
    
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   181
    // send
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   182
    send_all(NETMSG_PLAYER_SPAWN, pkt, true);
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   183
    
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   184
    // super
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   185
    Player::spawn(position);
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   186
}
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   187
        
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   188
void NetworkServerPlayer::die (bool start_timer) {
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   189
    NetworkPacket pkt;
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   190
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   191
    Engine::log(INFO, "server_player.die") << this;
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   192
    
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   193
    // send
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   194
    send_all(NETMSG_PLAYER_DIE, pkt, true);
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   195
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   196
    // super
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   197
    Player::die(start_timer);
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   198
}
e734d8e9bbb5 make spawn/die work over the network
terom
parents: 296
diff changeset
   199
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   200
void NetworkServerPlayer::on_disconnected (void) {
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   201
    NetworkPacket pkt;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   202
    
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
   203
    Engine::log(INFO, "server_player.disconnected") << this << ": node=" << node;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   204
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   205
    // remove from server
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   206
    server.handle_disconnect(this);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   207
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   208
    // tell other clients
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
   209
    send_all(NETMSG_PLAYER_QUIT, pkt, true);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   210
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   211
    // free
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   212
//    delete this;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   213
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   214
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   215
void NetworkServerPlayer::on_input (NetworkNode *src, NetworkPacketInput &pkt) {
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   216
    // sanity-check, other players shouldn't move
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   217
    if (src != node) {
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   218
        Engine::log(WARN, "server_player.on_input") << "packet from wrong src=" << src << ", node=" << node;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   219
        return;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   220
    }
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   221
    
239
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   222
    // read packet 
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 209
diff changeset
   223
    PlayerInput input = pkt.read_uint16();
334
0cf3f2be51eb transmit handleInput dt
terom
parents: 330
diff changeset
   224
    TimeMS dt = pkt.read_uint32();
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   225
255
99431fdb0dc8 add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents: 241
diff changeset
   226
//    Engine::log(INFO, "server_player.on_input") << "player=" << obj << ", old_pos=" << position << ", input=" << input;
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   227
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   228
    // apply input
334
0cf3f2be51eb transmit handleInput dt
terom
parents: 330
diff changeset
   229
    handleInput(input, dt);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   230
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   231
    // send position update
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   232
    send_position_update();
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   233
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   234
        
203
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   235
void NetworkServerPlayer::send_terrain_data (void) {
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   236
    Terrain &terrain = server.state.world;
282
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 276
diff changeset
   237
    
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 276
diff changeset
   238
    // XXX: over 2**31?
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 276
diff changeset
   239
    PixelDimension map_w = terrain.terrain.size();
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 276
diff changeset
   240
    PixelDimension map_h = terrain.terrain[0].size();
203
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   241
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   242
    // allocate our packet...
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   243
    BigNetworkPacket pkt (NETWORK_SESSION_HEADER_SIZE + 2 * sizeof(uint32_t) + map_w * map_h);
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   244
    
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   245
    // write netsession header
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   246
    node->write_packet_header(pkt, NETCHAN_TERRAIN_ARRAY);
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   247
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   248
    // write terrain dimensions
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   249
    pkt.write_uint32(map_w);
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   250
    pkt.write_uint32(map_h);
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   251
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   252
    // write out terrain data
282
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 276
diff changeset
   253
    for (PixelDimension x = 0; x < map_w; x++) {
e0e4dfc3e528 compiles cleanly with -Wall -Wextra -Wconversion, not tested, but that shouldn't break anything :)
terom
parents: 276
diff changeset
   254
        for (PixelDimension y = 0; y < map_h; y++) {
203
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   255
            pkt.write_uint8((uint8_t) terrain.terrain[x][y]);
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   256
        }
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   257
    }
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   258
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   259
    // send
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   260
    node->send_raw(pkt, true);
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   261
}
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
   262
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   263
void NetworkServerPlayer::send_position_update (void) {
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   264
    NetworkPacket pkt;
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   265
    
264
215de3d4de60 change facingRight from a bool to an
terom
parents: 263
diff changeset
   266
    int flags = 
215de3d4de60 change facingRight from a bool to an
terom
parents: 263
diff changeset
   267
        (inAir ? NETWORK_PHYSICS_INAIR : 0) | 
215de3d4de60 change facingRight from a bool to an
terom
parents: 263
diff changeset
   268
        (facing == FACING_RIGHT ? NETWORK_PHYSICS_FACE_RIGHT : 0);
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   269
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   270
    pkt.write_vector(position);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   271
    pkt.write_vector(velocity);
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   272
    pkt.write_uint8(flags);
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   273
    pkt.write_float32(aim);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   274
255
99431fdb0dc8 add PixelDimension/PixelCoordinate types, convert Terrain to use them, and convert/clean up drawing code
terom
parents: 241
diff changeset
   275
//    Engine::log(INFO, "server_player.send_position_update") << "obj=" << obj << " -> " << position << "+" << velocity << " [" << flags << "]";
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   276
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
   277
    send_all(NETMSG_PLAYER_POSITION, pkt, false);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   278
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   279
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   280
/* 
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   281
 * NetworkServerProjectile
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   282
 */
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
   283
NetworkServerProjectile::NetworkServerProjectile (NetworkServer &server, NetworkServerPlayer *player, Vector position,
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
   284
        Vector velocity, Weapon *weapon) :
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 275
diff changeset
   285
    Projectile(player, position, velocity, weapon, true), NetworkServerObject(server)
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   286
{
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   287
    NetworkPacket pkt;
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 275
diff changeset
   288
    
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 275
diff changeset
   289
    server.controller.write_object(pkt, player);
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   290
    pkt.write_vector(position);
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   291
    pkt.write_vector(velocity);
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 275
diff changeset
   292
    pkt.write_uint8(weapon->getID());
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   293
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 275
diff changeset
   294
    send_all(NETMSG_PROJECTILE_PLAYER_FIRED, pkt, true);
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   295
}
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   296
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   297
void NetworkServerProjectile::onDestroy (Vector position, bool removeGround) {
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   298
    NetworkPacket pkt;
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   299
296
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   300
    Engine::log(INFO, "server_projectile.destroy") << this << "position=" << position << ", removeGround=" << removeGround;
276
87434abc1ba1 ability to send NetworkObjectID's via packets, modify Network Projectiles to use this and fix recoil/reloading
terom
parents: 275
diff changeset
   301
    
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   302
    pkt.write_vector(position);
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   303
    pkt.write_uint8(removeGround ? NETWORK_PROJECTILE_REMOVE_GROUND : 0);
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   304
274
c35307e8645c add comments, move addPlayer/removePlayer to Player.cc, and refactor Network code to inherit from NetworkObject
terom
parents: 271
diff changeset
   305
    send_all(NETMSG_PROJECTILE_DESTROY, pkt, true);
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   306
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   307
    // XXX: leak obj, not yet implemented:  obj.destory();
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   308
    
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   309
    // pass on to super
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   310
    Projectile::onDestroy(position, removeGround);
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   311
}
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   312
330
dcc47278e5ab fix Network Projectile::onHitPlayer
terom
parents: 328
diff changeset
   313
void NetworkServerProjectile::onHitPlayer (Player *player_ptr) {
296
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   314
    NetworkPacket pkt;
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   315
    NetworkServerPlayer *player = dynamic_cast<NetworkServerPlayer*>(player_ptr);
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   316
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   317
    if (player == NULL) 
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   318
        throw Error("NetworkServerProjectile::onHitPlayer called with non-NetworkServerPlayer player");
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   319
    
330
dcc47278e5ab fix Network Projectile::onHitPlayer
terom
parents: 328
diff changeset
   320
    Engine::log(INFO, "server_projectile.hit_player") << this << ": player=" << player;
296
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   321
    
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   322
    // write packet
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   323
    controller.write_object(pkt, player);
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   324
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   325
    // send
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   326
    send_all(NETMSG_PROJECTILE_HIT_PLAYER, pkt, true);
304
d0f60a97a85e fix NetworkServerProjectile::onHitPlayer to call super
terom
parents: 302
diff changeset
   327
d0f60a97a85e fix NetworkServerProjectile::onHitPlayer to call super
terom
parents: 302
diff changeset
   328
    // super
308
60f4b55d5713 Calculates kills and deaths. You get frags by killing yourself \o/
saiam
parents: 304
diff changeset
   329
    Projectile::onHitPlayer(player_ptr);
296
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   330
}
4d3ebaa29430 add separate Types.hh, and fix projectile-worm collisions on network
terom
parents: 290
diff changeset
   331