src/Network/Client.cc
author terom
Sun, 07 Dec 2008 01:18:59 +0000
changeset 241 e95b1602d836
parent 239 550397d9d479
child 255 99431fdb0dc8
permissions -rw-r--r--
implement the ROT (Rope Over TCP) protocol
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"
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
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    10
NetworkClient::NetworkClient (GameState &state, const NetworkAddress &connect_to) : 
187
f41f894213ca restructure network code a bit
terom
parents: 186
diff changeset
    11
    state(state), netsession(NETWORK_MAGIC_ID), server(netsession.connect(connect_to)), netobjs(netsession, NETCHAN_CORE, server) {
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
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    14
    slots.connect(netobjs.sig_create(NETMSG_SERVER_HELLO), this, &NetworkClient::on_server_hello);
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    15
    slots.connect(netobjs.sig_create(NETMSG_PLAYER_INFO), this, &NetworkClient::on_player_info);
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    16
    slots.connect(netobjs.sig_create(NETMSG_PLAYER_JOIN), this, &NetworkClient::on_player_join);
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    17
    slots.connect(netobjs.sig_create(NETMSG_PROJECTILE_CREATE), this, &NetworkClient::on_projectile_create);
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    18
203
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    19
    slots.connect(netsession.sig_chan_message(NETCHAN_TERRAIN_ARRAY), this, &NetworkClient::on_terrain_array);
185
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
    // XXX: sig_disconnected
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    22
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    23
        
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
    24
void NetworkClient::on_server_hello (NetworkObject_Client *obj, NetworkPacketInput &pkt) {
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    25
    // read the packet
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    26
    Vector position = pkt.read_vector();
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    27
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    28
    Engine::log(INFO, "client.on_server_hello") << "obj=" << obj << ", pos=" << position;
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
    // create the LocalPlayer object
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    31
    NetworkClientLocalPlayer *player = new NetworkClientLocalPlayer(*this, obj, position);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    32
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    33
    // inform state
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    34
    state.newLocalPlayer(player);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    35
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    36
        
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
    37
void NetworkClient::on_player_info (NetworkObject_Client *obj, NetworkPacketInput &pkt) {
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    38
    // read the packet
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    39
    Vector position = pkt.read_vector();
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    40
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    41
    Engine::log(INFO, "client.on_player_info") << "obj=" << obj << ", pos=" << position;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    42
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    43
    // create the LocalPlayer object
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    44
    NetworkClientRemotePlayer *player = new NetworkClientRemotePlayer(*this, obj, position);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    45
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    46
    // inform state
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 203
diff changeset
    47
    state.newPlayer(player);
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    48
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    49
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    50
        
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
    51
void NetworkClient::on_player_join (NetworkObject_Client *obj, NetworkPacketInput &pkt) {
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    52
    // read the packet
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    53
    Vector position = pkt.read_vector();
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    54
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    55
    Engine::log(INFO, "client.on_player_join") << "obj=" << obj << ", pos=" << position;
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
    // create the RemotePlayer object
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    58
    NetworkClientRemotePlayer *player = new NetworkClientRemotePlayer(*this, obj, position);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    59
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    60
    // inform state
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 203
diff changeset
    61
    state.newPlayer(player);
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
        
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    64
void NetworkClient::on_projectile_create (NetworkObject_Client *obj, NetworkPacketInput &pkt) {
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    65
    // read the packet
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    66
    Vector position = pkt.read_vector();
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    67
    Vector velocity = pkt.read_vector();
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    68
    float explosionRadius = pkt.read_float32();
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    69
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    70
    Engine::log(INFO, "client.on_projectile_create") << "obj=" << obj << ", pos=" << position << ", velocity=" << velocity;
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    71
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    72
    // create the NetworkClientPorjectile object
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    73
    new NetworkClientProjectile(*this, obj, position, velocity, explosionRadius);
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    74
}
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
    75
        
203
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    76
void NetworkClient::on_terrain_array (NetworkPacketInput &pkt, NetworkNode *node) {
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    77
    // 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
    78
    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
    79
        return;
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    80
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    81
    Terrain &terrain = state.world;
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    82
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    83
    // read map width/height
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    84
    uint32_t map_w = pkt.read_uint32();
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    85
    uint32_t map_h = pkt.read_uint32();
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    86
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    87
    // read map data
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    88
    for (int x = 0; x < map_w; x++) {
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    89
        for (int y = 0; y < map_h; y++) {
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    90
            terrain.terrain[x][y] = (TerrainType) pkt.read_uint8();
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    91
        }
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    92
    }
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    93
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    94
    // update the pixbuf
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    95
    terrain.generatePixelBuffer();
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    96
}
3ec7ab40755f send initial terrain data to clients using a new NETCHAN_TERRAIN_ARRAY channel using raw BigNetworkPacket
terom
parents: 200
diff changeset
    97
        
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    98
void NetworkClient::player_quit (NetworkClientRemotePlayer *player) {
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
    99
    // inform state
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   100
    state.removePlayer(player);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   101
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   102
    // delete
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   103
    // XXX: leak because deleting the slot while it's being called breaks ClanLib
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   104
    //  delete player;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   105
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   106
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   107
/*
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   108
 * NetworkClientObjectHelper
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   109
 */
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   110
NetworkClientObjectHelper::NetworkClientObjectHelper (NetworkClient &client, NetworkObject_Client *obj) :
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   111
    client(client), obj(obj)
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   112
{
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   113
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   114
}
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   115
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   116
/*
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   117
 * NetworkClientPlayerHelper
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   118
 */
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 203
diff changeset
   119
NetworkClientPlayerHelper::NetworkClientPlayerHelper (NetworkClient &client, Vector position, NetworkObject_Client *obj) :
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   120
    NetworkClientObjectHelper(client, obj), Player(client.state, position, true) 
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   121
{
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   122
    slots.connect(obj->sig_message(NETMSG_PLAYER_POSITION),         this,   &NetworkClientPlayerHelper::on_position         );
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   123
    slots.connect(obj->sig_message(NETMSG_PLAYER_DIG),              this,   &NetworkClientPlayerHelper::on_dig              );
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   124
    slots.connect(obj->sig_message(NETMSG_PLAYER_WEAPON_CHANGE),    this,   &NetworkClientPlayerHelper::on_weapon_change    );
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   125
    slots.connect(obj->sig_message(NETMSG_PLAYER_ROPE_THROW),       this,   &NetworkClientPlayerHelper::on_rope_throw       );
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   126
    slots.connect(obj->sig_message(NETMSG_PLAYER_ROPE_FIXED),       this,   &NetworkClientPlayerHelper::on_rope_fixed       );
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   127
    slots.connect(obj->sig_message(NETMSG_PLAYER_ROPE_RELEASED),    this,   &NetworkClientPlayerHelper::on_rope_released    );
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   128
    slots.connect(obj->sig_message(NETMSG_PLAYER_ROPE_LENGTH),      this,   &NetworkClientPlayerHelper::on_rope_length      );
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   129
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   130
}
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   131
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   132
void NetworkClientPlayerHelper::on_position (NetworkPacketInput &pkt) {
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   133
    Vector position = pkt.read_vector();
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   134
    Vector velocity = pkt.read_vector();
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   135
    int flags = pkt.read_uint8();
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   136
    float aim = pkt.read_float32();
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   137
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   138
    Engine::log(INFO, "client_player.on_position") << "obj=" << obj << ", position=" << position << ", velocity=" << velocity << ", aim=" << aim << ", [" << flags << "]";
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   139
    
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   140
    // just update... 
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 203
diff changeset
   141
    updatePhysics(position, velocity, flags & NETWORK_PHYSICS_INAIR, flags & NETWORK_PHYSICS_FACE_RIGHT, aim);
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   142
}
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   143
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   144
void NetworkClientPlayerHelper::on_dig (NetworkPacketInput &pkt) {
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   145
    Vector position = pkt.read_vector();
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   146
    float radius = pkt.read_float32();
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   147
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   148
    Engine::log(INFO, "client_player.on_dig") << "obj=" << obj << ", position=" << position << ", radius=" << radius;
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   149
    
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   150
    // just update... 
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 203
diff changeset
   151
    handleDig(position, radius);
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   152
}
239
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   153
        
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   154
void NetworkClientPlayerHelper::on_weapon_change (NetworkPacketInput &pkt) {
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   155
    uint8_t weapon_index = pkt.read_uint8();
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   156
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   157
    Engine::log(INFO, "client_player.on_weapon_change") << "obj=" << obj << ", weapon_index=" << weapon_index;
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   158
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   159
    handleChangeWeapon(weapon_index);
550397d9d479 implement network weapon changes and fix weapon firing
terom
parents: 224
diff changeset
   160
}
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   161
241
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   162
void NetworkClientPlayerHelper::on_rope_throw (NetworkPacketInput &pkt) {
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   163
    Vector position = pkt.read_vector();
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   164
    Vector velocity = pkt.read_vector();
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   165
    float length = pkt.read_float32();
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   166
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   167
    Engine::log(INFO, "client_player.on_rope_throw") << "obj=" << obj << ", position=" << position << ", velocity=" << velocity << ", length=" << length;
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   168
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   169
    rope.updateState(ROPE_FLYING, position, velocity, length);
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   170
}
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   171
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   172
void NetworkClientPlayerHelper::on_rope_fixed (NetworkPacketInput &pkt) {
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   173
    Vector position = pkt.read_vector();
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   174
    float length = pkt.read_float32();
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   175
    
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   176
    Engine::log(INFO, "client_player.on_rope_fixed") << "obj=" << obj << ", position=" << position << ", length=" << length;
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   177
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   178
    rope.updateState(ROPE_FIXED, position, Vector(0, 0), length);
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   179
}
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   180
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   181
void NetworkClientPlayerHelper::on_rope_released (NetworkPacketInput &pkt) {
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   182
    Engine::log(INFO, "client_player.on_rope_released") << "obj=" << obj;
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   183
    
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   184
    // use rope.getPosition() instead of e.g. Vector(0, 0) because it will collide there...
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   185
    rope.updateState(ROPE_FOLDED, rope.getPosition(), Vector(0, 0), 0);
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   186
}
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   187
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   188
void NetworkClientPlayerHelper::on_rope_length (NetworkPacketInput &pkt) {
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   189
    float length = pkt.read_float32();
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   190
    
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   191
    Engine::log(INFO, "client_player.on_rope_length") << "obj=" << obj << ", length=" << length;
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   192
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   193
    rope.updateLength(length);
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   194
}
e95b1602d836 implement the ROT (Rope Over TCP) protocol
terom
parents: 239
diff changeset
   195
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   196
NetworkClientLocalPlayer::NetworkClientLocalPlayer (NetworkClient &client, NetworkObject_Client *obj, Vector position) :
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 203
diff changeset
   197
    Player(client.state, position, true), NetworkClientPlayerHelper(client, position, obj) {
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   198
    
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   199
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   200
        
221
fbc5db6fce45 reorganize the weapons code and input handling code
terom
parents: 209
diff changeset
   201
void NetworkClientLocalPlayer::handleInput (PlayerInput input) {
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   202
    // always send move, in all cases
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   203
    NetworkPacket pkt;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   204
    pkt.write_uint16(input);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   205
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   206
    obj->send(NETMSG_CLIENT_INPUT, pkt, false);
185
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
    // do not handle locally
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   209
}
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
NetworkClientRemotePlayer::NetworkClientRemotePlayer (NetworkClient &client, NetworkObject_Client *obj, Vector position) :
209
68cc4248a508 sneak in some ugly ugly ugly Multiple Inheritance that hopefully nobody ever notices
terom
parents: 203
diff changeset
   212
    Player(client.state, position, true), NetworkClientPlayerHelper(client, position, obj) {
185
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
    // receive messages
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   215
    slots.connect(obj->sig_message(NETMSG_PLAYER_QUIT), this, &NetworkClientRemotePlayer::on_quit);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   216
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   217
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   218
void NetworkClientRemotePlayer::on_quit (NetworkPacketInput &pkt) {
185
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   219
    // pkt is empty
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   220
    (void) pkt;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   221
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   222
    Engine::log(INFO, "client_player.on_quit") << "obj=" << obj;
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   223
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   224
    client.player_quit(this);
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   225
}
25becd2cb026 that's not a prototype anymore... at least it shouldn't be
terom
parents:
diff changeset
   226
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   227
NetworkClientProjectile::NetworkClientProjectile (NetworkClient &client, NetworkObject_Client *obj, Vector position,
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   228
        Vector velocity, float explosionRadius) :
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   229
    NetworkClientObjectHelper(client, obj), Projectile(client.state, position, velocity, true, explosionRadius)
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   230
{
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   231
    // hook up signals
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   232
    slots.connect(obj->sig_message(NETMSG_PROJECTILE_DESTROY), this, &NetworkClientProjectile::on_destroy);
223
2fcaf54ed37b basic network-projectiles
terom
parents: 221
diff changeset
   233
}
200
2dbf40661580 better NetworkBuffer/Packet stuff + some additional Physics+Network stuff + random fixes
terom
parents: 187
diff changeset
   234
224
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   235
void NetworkClientProjectile::onDestroy (Vector position, bool removeGround) {
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   236
    // ignore :>
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   237
}
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   238
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   239
void NetworkClientProjectile::on_destroy (NetworkPacketInput &pkt) {
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   240
    Vector position = pkt.read_vector();
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   241
    uint8_t flags = pkt.read_uint8();
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   242
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   243
    Engine::log(INFO, "client_projectile.on_destroy") << "obj=" << obj << ", position=" << position << ", flags=" << flags;
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   244
    
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   245
    // XXX: leak obj, not yet implemented:  obj.destory();
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   246
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   247
    // pass on to super
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   248
    Projectile::onDestroy(position, flags & NETWORK_PROJECTILE_REMOVE_GROUND);
e6faefba2ec1 fixed logger, and network projectiles should work reasonably well now
terom
parents: 223
diff changeset
   249
}