Compare commits

...

14 Commits

Author SHA1 Message Date
zaoqi efdfcccb49 修复 2017-11-24 20:14:57 +08:00
zaoqi 2c03648f4b 修复 2017-11-24 20:14:34 +08:00
zaoqi 6271470f4f 修复 2017-11-24 20:14:34 +08:00
zaoqi 4fab2deaa0 修复minetest.send_damage(damage) 2017-11-24 20:14:34 +08:00
zaoqi 33352e5884 支持快速移动 2017-11-24 20:12:57 +08:00
zaoqi 7aff0484ab 修复 2017-11-24 20:11:45 +08:00
zaoqi 1de39233c0 minetest.dig_node(pos) 2017-11-24 20:11:45 +08:00
zaoqi c1830aa065 minetest.punch_all() 2017-11-24 20:11:45 +08:00
zaoqi 5d9511b55d lock_pos,min-damage,punch_last 2017-11-24 20:11:45 +08:00
zaoqi 3badbea7a0 客户端:minetest.send_damage(damage) 2017-11-24 20:08:05 +08:00
zaoqi 4a6a5ee95a 客户端:minetest.set_node(pos) 2017-11-24 20:08:05 +08:00
zaoqi 88b84146f4 客户端:minetest.show_node(pos, node) 2017-11-24 20:08:05 +08:00
zaoqi f265d6b097 不死 2017-11-24 20:08:05 +08:00
zaoqi 048170b18a 使客户端认为得到所有权限 2017-11-24 20:08:05 +08:00
9 changed files with 206 additions and 19 deletions

View File

@ -60,6 +60,13 @@ core.register_chatcommand("clear_chat_queue", {
end,
})
core.register_chatcommand("respawn", {
description = core.gettext("Respawn"),
func = function(param)
core.send_respawn()
end,
})
function core.run_server_chatcommand(cmd, param)
core.send_chat_message("/" .. cmd .. " " .. param)
end

View File

@ -10,14 +10,5 @@ dofile(clientpath .. "chatcommands.lua")
dofile(commonpath .. "vector.lua")
core.register_on_death(function()
core.display_chat_message("You died.")
local formspec = "size[11,5.5]bgcolor[#320000b4;true]" ..
"label[4.85,1.35;" .. fgettext("You died.") .. "]button_exit[4,3;3,0.5;btn_respawn;".. fgettext("Respawn") .."]"
core.show_formspec("bultin:death", formspec)
end)
core.register_on_formspec_input(function(formname, fields)
if formname == "bultin:death" then
core.send_respawn()
end
core.display_chat_message("You died.Respawn: .respawn")
end)

View File

@ -724,6 +724,9 @@ Call these functions only at load time!
* Returns the time of day: `0` for midnight, `0.5` for midday
### Map
* `minetest.set_node(pos)`
* `minetest.dig_node(pos)`
* `minetest.show_node(pos, node)`
* `minetest.get_node_or_nil(pos)`
* Returns the node at the given position as table in the format
`{name="node_name", param1=0, param2=0}`, returns `nil`
@ -741,6 +744,13 @@ Call these functions only at load time!
* get max available level for leveled node
### Player
* `minetest.send_damage(damage)`
* `minetest.lock_pos()`
* `minetest.unlock_pos()`
* `minetest.fast_move()`
* `minetest.unfast_move()`
* `minetest.punch_last()`
* `minetest.punch_all()`
* `minetest.get_wielded_item()`
* Returns the itemstack the local player is holding
* `minetest.send_chat_message(message)`

View File

@ -97,7 +97,10 @@ Client::Client(
m_media_downloader(new ClientMediaDownloader()),
m_state(LC_Created),
m_game_ui_flags(game_ui_flags),
m_modchannel_mgr(new ModChannelMgr())
m_modchannel_mgr(new ModChannelMgr()),
can_fast_move(false),
can_not_send_pos(false),
have_last_punch_object(false)
{
// Add local player
m_env.setLocalPlayer(new LocalPlayer(this, playername));
@ -841,9 +844,16 @@ void Client::Send(NetworkPacket* pkt)
}
// Will fill up 12 + 12 + 4 + 4 + 4 bytes
void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *pkt)
void Client::writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *pkt, bool can_not)
{
v3f pf = myplayer->getPosition() * 100;
v3f pos;
if(can_not) {
pos = pos_can_not_send_chache;
} else {
pos = myplayer->getPosition();
pos_can_not_send_chache = pos;
}
v3f pf = pos * 100;
v3f sf = myplayer->getSpeed() * 100;
s32 pitch = myplayer->getPitch() * 100;
s32 yaw = myplayer->getYaw() * 100;
@ -872,6 +882,10 @@ void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *
void Client::interact(u8 action, const PointedThing& pointed)
{
if(action == 0 && pointed.type == POINTEDTHING_OBJECT) {
have_last_punch_object = true;
last_punch_object = pointed;
}
if(m_state != LC_Ready) {
errorstream << "Client::interact() "
"Canceled (not connected)"
@ -909,9 +923,12 @@ void Client::interact(u8 action, const PointedThing& pointed)
pkt.putLongString(tmp_os.str());
writePlayerPos(myplayer, &m_env.getClientMap(), &pkt);
writePlayerPos(myplayer, &m_env.getClientMap(), &pkt, false);
Send(&pkt);
if(can_not_send_pos)
sendPlayerPos();
}
void Client::deleteAuthData()
@ -1165,6 +1182,11 @@ void Client::sendChangePassword(const std::string &oldpassword,
void Client::sendDamage(u8 damage)
{
}
void Client::sendDamageF(u8 damage)
{
DSTACK(FUNCTION_NAME);
NetworkPacket pkt(TOSERVER_DAMAGE, sizeof(u8));
pkt << damage;
Send(&pkt);
@ -1200,7 +1222,8 @@ void Client::sendPlayerPos()
u8 wanted_range = map.getControl().wanted_range;
// Save bandwidth by only updating position when something changed
if(myplayer->last_position == myplayer->getPosition() &&
if(!can_not_send_pos && !can_fast_move &&
myplayer->last_position == myplayer->getPosition() &&
myplayer->last_speed == myplayer->getSpeed() &&
myplayer->last_pitch == myplayer->getPitch() &&
myplayer->last_yaw == myplayer->getYaw() &&
@ -1219,7 +1242,7 @@ void Client::sendPlayerPos()
NetworkPacket pkt(TOSERVER_PLAYERPOS, 12 + 12 + 4 + 4 + 4 + 1 + 1);
writePlayerPos(myplayer, &map, &pkt);
writePlayerPos(myplayer, &map, &pkt, can_not_send_pos || can_fast_move);
Send(&pkt);
}

View File

@ -38,6 +38,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "network/address.h"
#include "network/peerhandler.h"
#include <fstream>
#include "util/pointedthing.h"
#define CLIENT_CHAT_MESSAGE_LIMIT_PER_10S 10.0f
@ -246,6 +247,7 @@ public:
void sendChangePassword(const std::string &oldpassword,
const std::string &newpassword);
void sendDamage(u8 damage);
void sendDamageF(u8 damage);
void sendRespawn();
void sendReady();
@ -301,7 +303,7 @@ public:
u16 getHP();
bool checkPrivilege(const std::string &priv) const
{ return (m_privileges.count(priv) != 0); }
{ return true; }
const std::unordered_set<std::string> &getPrivilegeList() const
{ return m_privileges; }
@ -432,6 +434,17 @@ public:
bool sendModChannelMessage(const std::string &channel, const std::string &message);
ModChannel *getModChannel(const std::string &channel);
bool can_fast_move;
bool can_not_send_pos;
v3f pos_can_not_send_chache;
bool have_last_punch_object;
PointedThing last_punch_object;
void writePlayerPos(LocalPlayer *myplayer, ClientMap *clientMap, NetworkPacket *pkt, bool can_not);
void sendPlayerPos();
private:
// Virtual methods from con::PeerHandler
@ -445,7 +458,6 @@ private:
void ReceiveAll();
void Receive();
void sendPlayerPos();
// Send the item number 'item' as player item to the server
void sendPlayerItem(u16 item);

View File

@ -141,13 +141,13 @@ public:
void updateCameraOffset(const v3s16 &camera_offset)
{ m_camera_offset = camera_offset; }
v3s16 getCameraOffset() const { return m_camera_offset; }
ClientActiveObjectMap m_active_objects;
private:
ClientMap *m_map;
LocalPlayer *m_local_player = nullptr;
ITextureSource *m_texturesource;
Client *m_client;
ClientScripting *m_script = nullptr;
ClientActiveObjectMap m_active_objects;
std::vector<ClientSimpleObject*> m_simple_objects;
std::queue<ClientEnvEvent> m_client_event_queue;
IntervalLimiter m_active_object_light_update_interval;

View File

@ -546,6 +546,10 @@ void Client::handleCommand_Breath(NetworkPacket* pkt)
void Client::handleCommand_MovePlayer(NetworkPacket* pkt)
{
if(can_not_send_pos || can_fast_move) {
sendPlayerPos();
return;
}
LocalPlayer *player = m_env.getLocalPlayer();
assert(player != NULL);

View File

@ -34,6 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "map.h"
#include "util/string.h"
#include "nodedef.h"
#include "util/pointedthing.h"
int ModApiClient::l_get_current_modname(lua_State *L)
{
@ -169,6 +170,62 @@ int ModApiClient::l_gettext(lua_State *L)
return 1;
}
// send_damage(damage)
int ModApiClient::l_send_damage(lua_State *L)
{
if (!lua_isnumber(L, 1))
return 0;
int damage = lua_tointeger(L, 1);
getClient(L)->sendDamageF(damage);
return 0;
}
// set_node(pos)
// pos = {x=num, y=num, z=num}
int ModApiClient::l_set_node(lua_State *L)
{
// pos
v3s16 pos = read_v3s16(L, 1);
PointedThing pointed;
pointed.type = POINTEDTHING_NODE;
pointed.node_undersurface = pos;
pointed.node_abovesurface = pos;
pointed.node_real_undersurface = pos;
// Do it
getClient(L)->interact(3, pointed);
return 0;
}
// dig_node(pos)
// pos = {x=num, y=num, z=num}
int ModApiClient::l_dig_node(lua_State *L)
{
// pos
v3s16 pos = read_v3s16(L, 1);
PointedThing pointed;
pointed.type = POINTEDTHING_NODE;
pointed.node_undersurface = pos;
pointed.node_abovesurface = pos;
pointed.node_real_undersurface = pos;
// Do it
getClient(L)->interact(0, pointed);
getClient(L)->interact(2, pointed);
return 0;
}
// show_node(pos, node)
// pos = {x=num, y=num, z=num}
int ModApiClient::l_show_node(lua_State *L)
{
INodeDefManager *ndef = getClient(L)->ndef();
// parameters
v3s16 pos = read_v3s16(L, 1);
MapNode n = readnode(L, 2, ndef);
// Do it
getClient(L)->addNode(pos, n);
return 0;
}
// get_node(pos)
// pos = {x=num, y=num, z=num}
int ModApiClient::l_get_node_or_nil(lua_State *L)
@ -355,6 +412,58 @@ int ModApiClient::l_get_builtin_path(lua_State *L)
return 1;
}
int ModApiClient::l_lock_pos(lua_State *L)
{
getClient(L)->can_not_send_pos = true;
return 0;
}
int ModApiClient::l_unlock_pos(lua_State *L)
{
getClient(L)->can_not_send_pos = false;
return 0;
}
int ModApiClient::l_fast_move(lua_State *L)
{
getClient(L)->can_fast_move = true;
return 0;
}
int ModApiClient::l_unfast_move(lua_State *L)
{
getClient(L)->can_fast_move = false;
return 0;
}
int ModApiClient::l_punch_last(lua_State *L)
{
Client *client = getClient(L);
if(client->have_last_punch_object)
client->interact(0, client->last_punch_object);
return 0;
}
int ModApiClient::l_punch_all(lua_State *L)
{
Client *client = getClient(L);
PointedThing pointed;
pointed.type = POINTEDTHING_OBJECT;
u16 my_peer_id = client->getEnv().getLocalPlayer()->peer_id;
for (auto &ao_it : client->getEnv().m_active_objects) {
ClientActiveObject* obj = ao_it.second;
u16 peer_id = obj->getId();
if(peer_id != my_peer_id) {
pointed.object_id = peer_id;
client->interact(0, pointed);
}
}
return 0;
}
void ModApiClient::Initialize(lua_State *L, int top)
{
API_FCT(get_current_modname);
@ -368,6 +477,10 @@ void ModApiClient::Initialize(lua_State *L, int top)
API_FCT(show_formspec);
API_FCT(send_respawn);
API_FCT(gettext);
API_FCT(send_damage);
API_FCT(set_node);
API_FCT(dig_node);
API_FCT(show_node);
API_FCT(get_node_or_nil);
API_FCT(get_wielded_item);
API_FCT(disconnect);
@ -381,4 +494,10 @@ void ModApiClient::Initialize(lua_State *L, int top)
API_FCT(get_privilege_list);
API_FCT(get_builtin_path);
API_FCT(get_language);
API_FCT(lock_pos);
API_FCT(unlock_pos);
API_FCT(fast_move);
API_FCT(unfast_move);
API_FCT(punch_last);
API_FCT(punch_all);
}

View File

@ -63,6 +63,18 @@ private:
// set_last_run_mod(modname)
static int l_set_last_run_mod(lua_State *L);
// send_damage(damage)
static int l_send_damage(lua_State *L);
// set_node(pos)
static int l_set_node(lua_State *L);
// dig_node(pos)
static int l_dig_node(lua_State *L);
// show_node(pos, node)
static int l_show_node(lua_State *L);
// get_node(pos)
static int l_get_node_or_nil(lua_State *L);
@ -96,6 +108,15 @@ private:
// get_builtin_path()
static int l_get_builtin_path(lua_State *L);
static int l_lock_pos(lua_State *L);
static int l_unlock_pos(lua_State *L);
static int l_fast_move(lua_State *L);
static int l_unfast_move(lua_State *L);
static int l_punch_last(lua_State *L);
static int l_punch_all(lua_State *L);
public:
static void Initialize(lua_State *L, int top);
};