Compare commits

...

5 Commits

Author SHA1 Message Date
Perttu Ahola 569156b013 Call this 0.4.dev-20120106-1 2012-01-06 20:41:52 +02:00
Perttu Ahola 6d4bc012f0 Fix key change menu a bit 2012-01-06 19:50:40 +02:00
Perttu Ahola 2f5c28aaf1 ObjectRef:setpos() to move player properly (a bit shortcuttish implementation) 2012-01-06 19:17:44 +02:00
Perttu Ahola 4f2c1e36a1 Implement minetest.register_on_dieplayer() 2012-01-06 00:12:33 +02:00
Perttu Ahola bc743ca7ce Add missing checks to texture caching 2012-01-04 00:37:46 +02:00
9 changed files with 88 additions and 22 deletions

View File

@ -10,7 +10,7 @@ project(minetest)
# Also remember to set PROTOCOL_VERSION in clientserver.h when releasing
set(VERSION_MAJOR 0)
set(VERSION_MINOR 4)
set(VERSION_PATCH dev-20120102-1)
set(VERSION_PATCH dev-20120106-1)
set(VERSION_STRING "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
MESSAGE(STATUS "*** Will build version ${VERSION_STRING} ***")

View File

@ -435,6 +435,7 @@ minetest.registered_on_dignodes, minetest.register_on_dignode = make_registratio
minetest.registered_on_punchnodes, minetest.register_on_punchnode = make_registration()
minetest.registered_on_generateds, minetest.register_on_generated = make_registration()
minetest.registered_on_newplayers, minetest.register_on_newplayer = make_registration()
minetest.registered_on_dieplayers, minetest.register_on_dieplayer = make_registration()
minetest.registered_on_respawnplayers, minetest.register_on_respawnplayer = make_registration()
-- END

View File

@ -101,8 +101,10 @@
-- minetest.register_on_punchnode(func(pos, node, puncher))
-- minetest.register_on_generated(func(minp, maxp))
-- minetest.register_on_newplayer(func(ObjectRef))
-- minetest.register_on_dieplayer(func(ObjectRef))
-- minetest.register_on_respawnplayer(func(ObjectRef))
-- ^ return true in func to disable regular player placement
-- ^ currently called _before_ repositioning of player occurs
-- minetest.register_on_chat_message(func(name, message))
-- minetest.add_to_creative_inventory(itemstring)
-- minetest.setting_get(name) -> string or nil

View File

@ -1276,6 +1276,13 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
//read texture from cache
std::string name = deSerializeString(is);
std::string sha1_texture = deSerializeString(is);
// if name contains illegal characters, ignore the texture
if(!string_allowed(name, TEXTURENAME_ALLOWED_CHARS)){
errorstream<<"Client: ignoring illegal texture name "
<<"sent by server: \""<<name<<"\""<<std::endl;
continue;
}
std::string tpath = getTextureCacheDir() + DIR_DELIM + name;
// Read data
@ -1371,8 +1378,6 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
for each texture {
u16 length of name
string name
u16 length of path
string path
}
*/
std::ostringstream os(std::ios_base::binary);
@ -1439,6 +1444,14 @@ void Client::ProcessData(u8 *data, u32 datasize, u16 sender_peer_id)
for(int i=0; i<num_textures; i++){
std::string name = deSerializeString(is);
std::string data = deSerializeLongString(is);
// if name contains illegal characters, ignore the texture
if(!string_allowed(name, TEXTURENAME_ALLOWED_CHARS)){
errorstream<<"Client: ignoring illegal texture name "
<<"sent by server: \""<<name<<"\""<<std::endl;
continue;
}
// Silly irrlicht's const-incorrectness
Buffer<char> data_rw(data.c_str(), data.size());
// Create an irrlicht memory file

View File

@ -48,6 +48,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#define PASSWORD_SIZE 28 // Maximum password length. Allows for
// base64-encoded SHA-1 (27+\0).
#define TEXTURENAME_ALLOWED_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_."
enum ToClientCommand
{
TOCLIENT_INIT = 0x10,

View File

@ -181,13 +181,13 @@ irr::EKEY_CODE keyname_to_keycode(const char *name)
}
static const char *KeyNames[] =
{ "-", "KEY_LBUTTON", "KEY_RBUTTON", "Cancel", "Middle Button", "X Button 1",
"X Button 2", "-", "Back", "Tab", "-", "-", "Clear", "Return", "-",
"-", "KEY_SHIFT", "Control", "Menu", "Pause", "Capital", "Kana", "-",
"Junja", "Final", "Kanji", "-", "Escape", "Convert", "Nonconvert",
"Accept", "Mode Change", "KEY_SPACE", "Priot", "Next", "KEY_END",
"KEY_HOME", "Left", "Up", "Right", "Down", "Select", "KEY_PRINT",
"Execute", "Snapshot", "Insert", "Delete", "Help", "KEY_KEY_0",
{ "-", "KEY_LBUTTON", "KEY_RBUTTON", "KEY_CANCEL", "KEY_MBUTTON", "KEY_XBUTTON1",
"KEY_XBUTTON2", "-", "KEY_BACK", "KEY_TAB", "-", "-", "KEY_CLEAR", "KEY_RETURN", "-",
"-", "KEY_SHIFT", "KEY_CONTROL", "KEY_MENU", "KEY_PAUSE", "KEY_CAPITAL", "KEY_KANA", "-",
"KEY_JUNJA", "KEY_FINAL", "KEY_KANJI", "-", "KEY_ESCAPE", "KEY_CONVERT", "KEY_NONCONVERT",
"KEY_ACCEPT", "KEY_MODECHANGE", "KEY_SPACE", "KEY_PRIOR", "KEY_NEXT", "KEY_END",
"KEY_HOME", "KEY_LEFT", "KEY_UP", "KEY_RIGHT", "KEY_DOWN", "KEY_SELECT", "KEY_PRINT",
"KEY_EXECUTE", "KEY_SNAPSHOT", "KEY_INSERT", "KEY_DELETE", "KEY_HELP", "KEY_KEY_0",
"KEY_KEY_1", "KEY_KEY_2", "KEY_KEY_3", "KEY_KEY_4", "KEY_KEY_5",
"KEY_KEY_6", "KEY_KEY_7", "KEY_KEY_8", "KEY_KEY_9", "-", "-", "-", "-",
"-", "-", "-", "KEY_KEY_A", "KEY_KEY_B", "KEY_KEY_C", "KEY_KEY_D",
@ -195,25 +195,25 @@ static const char *KeyNames[] =
"KEY_KEY_J", "KEY_KEY_K", "KEY_KEY_L", "KEY_KEY_M", "KEY_KEY_N",
"KEY_KEY_O", "KEY_KEY_P", "KEY_KEY_Q", "KEY_KEY_R", "KEY_KEY_S",
"KEY_KEY_T", "KEY_KEY_U", "KEY_KEY_V", "KEY_KEY_W", "KEY_KEY_X",
"KEY_KEY_Y", "KEY_KEY_Z", "Left Windows", "Right Windows", "Apps", "-",
"Sleep", "KEY_NUMPAD0", "KEY_NUMPAD1", "KEY_NUMPAD2", "KEY_NUMPAD3",
"KEY_KEY_Y", "KEY_KEY_Z", "KEY_LWIN", "KEY_RWIN", "KEY_APPS", "-",
"KEY_SLEEP", "KEY_NUMPAD0", "KEY_NUMPAD1", "KEY_NUMPAD2", "KEY_NUMPAD3",
"KEY_NUMPAD4", "KEY_NUMPAD5", "KEY_NUMPAD6", "KEY_NUMPAD7",
"KEY_NUMPAD8", "KEY_NUMPAD9", "Numpad *", "Numpad +", "Numpad /",
"Numpad -", "Numpad .", "Numpad /", "KEY_F1", "KEY_F2", "KEY_F3",
"KEY_NUMPAD8", "KEY_NUMPAD9", "KEY_MULTIPLY", "KEY_ADD", "KEY_SEPERATOR",
"KEY_SUBTRACT", "KEY_DECIMAL", "KEY_DIVIDE", "KEY_F1", "KEY_F2", "KEY_F3",
"KEY_F4", "KEY_F5", "KEY_F6", "KEY_F7", "KEY_F8", "KEY_F9", "KEY_F10",
"KEY_F11", "KEY_F12", "KEY_F13", "KEY_F14", "KEY_F15", "KEY_F16",
"KEY_F17", "KEY_F18", "KEY_F19", "KEY_F20", "KEY_F21", "KEY_F22",
"KEY_F23", "KEY_F24", "-", "-", "-", "-", "-", "-", "-", "-",
"Num Lock", "Scroll Lock", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "KEY_LSHIFT", "KEY_RSHIFT", "Left Control",
"Right Control", "Left Menu", "Right Menu", "-", "-", "-", "-", "-",
"KEY_NUMLOCK", "KEY_SCROLL", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "KEY_LSHIFT", "KEY_RSHIFT", "KEY_LCONTROL",
"KEY_RCONTROL", "KEY_LMENU", "KEY_RMENU", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "Plus", "Comma", "Minus", "Period", "-", "-", "-", "-", "-",
"-", "-", "KEY_PLUS", "KEY_COMMA", "KEY_MINUS", "KEY_PERIOD", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-", "-",
"-", "-", "-", "-", "-", "-", "-", "-", "Attn", "CrSel", "ExSel",
"Erase OEF", "Play", "Zoom", "PA1", "OEM Clear", "-" };
"-", "-", "-", "-", "-", "-", "-", "-", "KEY_ATTN", "KEY_CRSEL", "KEY_EXSEL",
"KEY_EREOF", "KEY_PLAY", "KEY_ZOOM", "KEY_PA1", "KEY_OEM_CLEAR", "-" };
#define N_(text) text

View File

@ -1747,6 +1747,10 @@ private:
v3f pos = checkFloatPos(L, 2);
// Do it
co->setPos(pos);
// Move player if applicable
ServerRemotePlayer *player = getplayer(ref);
if(player != NULL)
get_server(L)->SendMovePlayer(player);
return 0;
}
@ -3638,6 +3642,32 @@ void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player)
// value removed, keep key for next iteration
}
}
void scriptapi_on_dieplayer(lua_State *L, ServerActiveObject *player)
{
realitycheck(L);
assert(lua_checkstack(L, 20));
StackUnroller stack_unroller(L);
// Get minetest.registered_on_dieplayers
lua_getglobal(L, "minetest");
lua_getfield(L, -1, "registered_on_dieplayers");
luaL_checktype(L, -1, LUA_TTABLE);
int table = lua_gettop(L);
// Foreach
lua_pushnil(L);
while(lua_next(L, table) != 0){
// key at index -2 and value at index -1
luaL_checktype(L, -1, LUA_TFUNCTION);
// Call function
objectref_get_or_create(L, player);
if(lua_pcall(L, 1, 0, 0))
script_error(L, "error: %s", lua_tostring(L, -1));
// value removed, keep key for next iteration
}
}
bool scriptapi_on_respawnplayer(lua_State *L, ServerActiveObject *player)
{
realitycheck(L);

View File

@ -62,6 +62,7 @@ void scriptapi_environment_on_generated(lua_State *L, v3s16 minp, v3s16 maxp);
/* misc */
void scriptapi_on_newplayer(lua_State *L, ServerActiveObject *player);
void scriptapi_on_dieplayer(lua_State *L, ServerActiveObject *player);
bool scriptapi_on_respawnplayer(lua_State *L, ServerActiveObject *player);
void scriptapi_get_creative_inventory(lua_State *L, ServerRemotePlayer *player);

View File

@ -4273,6 +4273,12 @@ void Server::PrepareTextures() {
if(dirlist[j].dir) // Ignode dirs
continue;
std::string tname = dirlist[j].name;
// if name contains illegal characters, ignore the texture
if(!string_allowed(tname, TEXTURENAME_ALLOWED_CHARS)){
errorstream<<"Server: ignoring illegal texture name: \""
<<tname<<"\""<<std::endl;
continue;
}
std::string tpath = texturepath + DIR_DELIM + tname;
// Read data
std::ifstream fis(tpath.c_str(), std::ios_base::binary);
@ -4300,6 +4306,11 @@ void Server::PrepareTextures() {
<<tname<<"\""<<std::endl;
continue;
}
if(tmp_os.str().length() == 0){
errorstream<<"Server::PrepareTextures(): Empty file \""
<<tpath<<"\""<<std::endl;
continue;
}
SHA1 sha1;
sha1.addBytes(tmp_os.str().c_str(), tmp_os.str().length());
@ -4332,7 +4343,7 @@ struct SendableTextureAnnouncement
void Server::SendTextureAnnouncement(u16 peer_id){
DSTACK(__FUNCTION_NAME);
infostream<<"Server::SendTextureAnnouncement(): Calculate sha1 sums of textures and send to client"<<std::endl;
infostream<<"Server::SendTextureAnnouncement()"<<std::endl;
core::list<SendableTextureAnnouncement> texture_announcements;
@ -4407,6 +4418,11 @@ void Server::SendTexturesRequested(u16 peer_id,core::list<TextureRequest> tosend
u32 texture_size_bunch_total = 0;
for(core::list<TextureRequest>::Iterator i = tosend.begin(); i != tosend.end(); i++) {
if(m_Textures.find(i->name) == m_Textures.end()){
errorstream<<"Server::SendTexturesRequested(): Client asked for "
<<"unknown texture \""<<(i->name)<<"\""<<std::endl;
continue;
}
//TODO get path + name
std::string tpath = m_Textures[(*i).name].path;
@ -4521,7 +4537,8 @@ void Server::HandlePlayerHP(Player *player, s16 damage)
player->hp = 0;
//TODO: Throw items around
// Trigger scripted stuff
scriptapi_on_dieplayer(m_lua, srp);
// Handle players that are not connected
if(player->peer_id == PEER_ID_INEXISTENT){