void Client::sendPlayerPos() { LocalPlayer *myplayer = m_env.getLocalPlayer(); if (!myplayer) return; ClientMap &map = m_env.getClientMap(); u8 camera_fov = map.getCameraFov(); u8 wanted_range = map.getControl().wanted_range; // Save bandwidth by only updating position when something changed if(myplayer->last_position == myplayer->getPosition() && myplayer->last_speed == myplayer->getSpeed() && myplayer->last_pitch == myplayer->getPitch() && myplayer->last_yaw == myplayer->getYaw() && myplayer->last_keyPressed == myplayer->keyPressed && myplayer->last_camera_fov == camera_fov && myplayer->last_wanted_range == wanted_range) return; myplayer->last_position = myplayer->getPosition(); myplayer->last_speed = myplayer->getSpeed(); myplayer->last_pitch = myplayer->getPitch(); myplayer->last_yaw = myplayer->getYaw(); myplayer->last_keyPressed = myplayer->keyPressed; myplayer->last_camera_fov = camera_fov; myplayer->last_wanted_range = wanted_range; NetworkPacket pkt(TOSERVER_PLAYERPOS, 12 + 12 + 4 + 4 + 4 + 1 + 1); writePlayerPos(myplayer, &map, &pkt); Send(&pkt); }
void Client::sendPlayerPos() { LocalPlayer *myplayer = m_env.getLocalPlayer(); if(myplayer == NULL) return; ClientMap &map = m_env.getClientMap(); u8 camera_fov = map.getCameraFov(); u8 wanted_range = map.getControl().wanted_range; // Save bandwidth by only updating position when something changed if(myplayer->last_position == myplayer->getPosition() && myplayer->last_speed == myplayer->getSpeed() && myplayer->last_pitch == myplayer->getPitch() && myplayer->last_yaw == myplayer->getYaw() && myplayer->last_keyPressed == myplayer->keyPressed && myplayer->last_camera_fov == camera_fov && myplayer->last_wanted_range == wanted_range) return; myplayer->last_position = myplayer->getPosition(); myplayer->last_speed = myplayer->getSpeed(); myplayer->last_pitch = myplayer->getPitch(); myplayer->last_yaw = myplayer->getYaw(); myplayer->last_keyPressed = myplayer->keyPressed; myplayer->last_camera_fov = camera_fov; myplayer->last_wanted_range = wanted_range; //infostream << "Sending Player Position information" << std::endl; u16 our_peer_id; { //MutexAutoLock lock(m_con_mutex); //bulk comment-out our_peer_id = m_con.GetPeerID(); } // Set peer id if not set already if(myplayer->peer_id == PEER_ID_INEXISTENT) myplayer->peer_id = our_peer_id; assert(myplayer->peer_id == our_peer_id); NetworkPacket pkt(TOSERVER_PLAYERPOS, 12 + 12 + 4 + 4 + 4 + 1 + 1); writePlayerPos(myplayer, &map, &pkt); Send(&pkt); }
void Client::interact(u8 action, const PointedThing& pointed) { if(m_state != LC_Ready) { errorstream << "Client::interact() " "Canceled (not connected)" << std::endl; return; } LocalPlayer *myplayer = m_env.getLocalPlayer(); if (myplayer == NULL) return; /* [0] u16 command [2] u8 action [3] u16 item [5] u32 length of the next item (plen) [9] serialized PointedThing [9 + plen] player position information actions: 0: start digging (from undersurface) or use 1: stop digging (all parameters ignored) 2: digging completed 3: place block or item (to abovesurface) 4: use item 5: perform secondary action of item */ NetworkPacket pkt(TOSERVER_INTERACT, 1 + 2 + 0); pkt << action; pkt << (u16)getPlayerItem(); std::ostringstream tmp_os(std::ios::binary); pointed.serialize(tmp_os); pkt.putLongString(tmp_os.str()); writePlayerPos(myplayer, &m_env.getClientMap(), &pkt); Send(&pkt); }