Skip to content
Browse files

Fix for inventory click-and-drag actions. Changed commands-plugin to …

…display only the commands you can use
  • Loading branch information...
1 parent 5794408 commit 1fb9784b1b54ed87908a96c2ef5851ea03f458cf @fador committed
Showing with 114 additions and 12 deletions.
  1. +3 −0 include/inventory.h
  2. +3 −0 include/user.h
  3. +44 −6 plugins/commands/commands.cpp
  4. +3 −2 plugins/luascript/luascript.cpp
  5. +59 −3 src/inventory.cpp
  6. +2 −1 src/user.cpp
View
3 include/inventory.h
@@ -88,12 +88,15 @@ typedef std::tr1::shared_ptr<Item> ItemPtr;
struct OpenInventory
{
+ OpenInventory(): recordAction(false){};
int8_t type;
int32_t x;
int32_t y;
int32_t z;
Item workbench[10];
std::vector<User*> users;
+ std::vector<int16_t> slotActions;
+ bool recordAction;
};
typedef std::tr1::shared_ptr<OpenInventory> OpenInvPtr;
View
3 include/user.h
@@ -95,11 +95,14 @@ class User
std::string temp_nick;
vec curChunk;
time_t healthtimeout;
+
+ /* INVENTORY RELATED HELPERS */
Item inventoryHolding;
//Do we have an open _shared_ inventory?
bool isOpenInv;
//More info on the inventory
OpenInventory openInv;
+
std::string secret;
EVP_CIPHER_CTX en, de;
std::string generateDigest();
View
50 plugins/commands/commands.cpp
@@ -790,12 +790,11 @@ void sendRules(std::string user, std::string command, std::deque<std::string> ar
}
}
void about(std::string user, std::string command, std::deque<std::string> args)
-{
- std::ostringstream msg;
+{
if (mineserver->config.bData("system.show_version"))
{
- msg << "§9" << mineserver->config.sData("system.server_name") << " Running Mineserver v." << VERSION_SIMPLE;
- mineserver->chat.sendmsgTo(user.c_str(), msg.str().c_str());
+ std::string msg = std::string("§9") + std::string(mineserver->config.sData("system.server_name")) + std::string(" Running Mineserver v.") + std::string(VERSION_SIMPLE);
+ mineserver->chat.sendmsgTo(user.c_str(), msg.c_str());
}
}
@@ -809,11 +808,50 @@ void sendHelp(std::string user, std::string command, std::deque<std::string> arg
if (args.size() == 0)
{
+ bool isAdmin = mineserver->permissions.isAdmin(user.c_str());
+ bool isOp = mineserver->permissions.isOp(user.c_str());
+ bool isMember = mineserver->permissions.isMember(user.c_str());
+
for(CommandList::iterator it = commandList->begin();it != commandList->end();++it)
{
+ //Display only commands you can use and add !A!, !O! or !M! to signal who can use those
+ std::string msg;
+ if(it->second->needAdmin)
+ {
+ if(!isAdmin)
+ {
+ continue;
+ }
+ else
+ {
+ msg += "§o§c!A!§r ";
+ }
+ }
+ if(it->second->needOp)
+ {
+ if(!isOp)
+ {
+ continue;
+ }
+ else
+ {
+ msg += "§o§c!O!§r ";
+ }
+ }
+ if(it->second->needMember)
+ {
+ if(!isMember)
+ {
+ continue;
+ }
+ else
+ {
+ msg += "§o§c!M!§r ";
+ }
+ }
std::string args = it->second->arguments;
std::string description = it->second->description;
- std::string msg = /*commandColor +*/ CHATCMDPREFIX + it->first + " " + args + " : " /*+ MC_COLOR_YELLOW*/ + description;
+ msg += /*commandColor +*/ CHATCMDPREFIX + it->first + " " + args + " : " /*+ MC_COLOR_YELLOW*/ + description;
mineserver->chat.sendmsgTo(user.c_str(), msg.c_str());
}
}
@@ -906,7 +944,7 @@ PLUGIN_API_EXPORT void CALLCONVERSION commands_init(mineserver_pointer_struct* m
mineserver->plugin.addCallback("PlayerDiggingStarted", reinterpret_cast<voidF>(startedDiggingFunction));
registerCommand(ComPtr(new Command(parseCmd("about"), "", "Displays server name and software version", about)));
- registerCommand(ComPtr(new Command(parseCmd("ctp"), "<x> <y> <z>", "Teleport to coordinates (eg. /ctp 100 100 100)", coordinateTeleport)));
+ registerCommand(ComPtr(new Command(parseCmd("ctp"), "<x> <y> <z>", "Teleport to coordinates (eg. /ctp 100 100 100)", coordinateTeleport,false,false,true)));
registerCommand(ComPtr(new Command(parseCmd("cuboid"), "", "Type in the command and place two blocks, it will fill the space between them", cuboid,false,true)));
registerCommand(ComPtr(new Command(parseCmd("dnd"), "", "Toggles Do Not Disturb mode", doNotDisturb)));
registerCommand(ComPtr(new Command(parseCmd("flattenchunk"), "<id/alias>", "Erases all blocks above you and changes all blocks at your Y-level to your block of choice", flattenchunk, false,true)));
View
5 plugins/luascript/luascript.cpp
@@ -1,5 +1,5 @@
/*
- Copyright (c) 2012, The Mineserver Project
+ Copyright (c) 2013, The Mineserver Project
All rights reserved.
Redistribution and use in source and binary forms, with or without
@@ -161,6 +161,7 @@ bool blockPlacePreFunction(const char* userIn, int32_t x,int8_t y,int32_t z,int1
void sendHelp(std::string user, std::string command, std::deque<std::string> args)
{
+ if(!mineserver->permissions.isAdmin(user.c_str())) return;
CommandList* commandList = &m_Commands; // defaults
//std::string commandColor = MC_COLOR_BLUE;
@@ -172,7 +173,7 @@ void sendHelp(std::string user, std::string command, std::deque<std::string> arg
{
std::string args = it->second->arguments;
std::string description = it->second->description;
- std::string msg = CHATCMDPREFIX + it->first + " " + args + " : " + description;
+ std::string msg = "§i§c!A!§r "+ CHATCMDPREFIX + it->first + " " + args + " : " + description;
mineserver->chat.sendmsgTo(user.c_str(), msg.c_str());
}
}
View
62 src/inventory.cpp
@@ -464,20 +464,76 @@ bool Inventory::canBeArmour(int slot, int type)
bool Inventory::windowClick(User* user, int8_t windowID, int16_t slot, int8_t rightClick, int16_t actionNumber, int16_t itemID, int8_t itemCount, int16_t itemUses, int8_t shift)
{
//Ack
- user->buffer << (int8_t)PACKET_TRANSACTION << (int8_t)windowID << (int16_t)actionNumber << (int8_t)1;
+ if(actionNumber)
+ {
+ user->buffer << (int8_t)PACKET_TRANSACTION << (int8_t)windowID << (int16_t)actionNumber << (int8_t)1;
+ }
//Click outside the window
if (slot == -999)
{
- if (user->inventoryHolding.getType() != -1)
+ //Dropping outside of the window
+ if(rightClick == 0 && shift == 0 && user->inventoryHolding.getType() != -1)
{
ServerInstance->map(user->pos.map)->createPickupSpawn((int)user->pos.x, (int)user->pos.y, (int)user->pos.z,
user->inventoryHolding.getType(), user->inventoryHolding.getCount(),
user->inventoryHolding.getHealth(), user);
user->inventoryHolding.setType(-1);
+ return true;
+ }
+ if(shift == 5 && user->inventoryHolding.getType() != -1)
+ {
+ //Right click-and-drag, just ignore for now (begin and end)
+ if(rightClick == 4 || rightClick == 6)
+ {
+ return true;
+ }
+ //Left click-and-drag (begin)
+ else if(rightClick == 0)
+ {
+ user->openInv.slotActions.clear();
+ user->openInv.recordAction = true;
+ return true;
+ }
+ //Left click-and-drag (end)
+ else if(rightClick == 2)
+ {
+ user->openInv.recordAction = false;
+
+ //Spread the stack nice and evenly
+ if(user->openInv.slotActions.size() > user->inventoryHolding.getCount())
+ {
+ //FAILURE (should not happend)
+ return true;
+ }
+ //HAX
+ int16_t count = (user->inventoryHolding.getCount()/user->openInv.slotActions.size());
+ for(int i = 0; i < user->openInv.slotActions.size(); i++)
+ {
+ for(int c = 0; c < count; c++)
+ {
+ windowClick(user, windowID, user->openInv.slotActions[i], 1, 0, -1, itemCount, itemUses, 0);
+ }
+ }
+ }
+ return true;
+ }
+
+ //printf("slot: %d, rightClick: %d, action: %d, shift: %d, item: %d\r\n", slot, rightClick, actionNumber,shift, itemID);
+
+ }
+ else if(user->openInv.recordAction)
+ {
+ if(shift == 5)
+ {
+ user->openInv.slotActions.push_back(slot);
+ }
+ else
+ {
+ user->openInv.recordAction = false;
}
- return true;
}
+ //printf("NON -999 slot: %d, rightClick: %d, action: %d, shift: %d, item: %d\r\n", slot,rightClick, actionNumber,shift, itemID);
if (!user->isOpenInv && windowID != 0)
{
View
3 src/user.cpp
@@ -1122,13 +1122,14 @@ bool User::spawnOthers()
// if ((*it)->logged && (*it)->UID != this->UID && (*it)->nick != this->nick)
if ((*it)->logged)
{
- loginBuffer << Protocol::namedEntitySpawn((*it)->UID, (*it)->nick, (*it)->pos.x, (*it)->pos.y, (*it)->pos.z, 0, 0, 0);
+ loginBuffer << Protocol::namedEntitySpawn((*it)->UID, (*it)->nick, (*it)->pos.x, (*it)->pos.y, (*it)->pos.z, angleToByte((*it)->pos.yaw),angleToByte((*it)->pos.pitch), 0);
for (int b = 0; b < 5; b++)
{
const int n = b == 0 ? (*it)->curItem + 36 : 9 - b;
const int type = (*it)->inv[n].getType();
loginBuffer << Protocol::entityEquipment((*it)->UID, b, type, 0);
}
+ loginBuffer << Protocol::entityHeadLook((*it)->UID,angleToByte((*it)->pos.yaw));
}
}
return true;

0 comments on commit 1fb9784

Please sign in to comment.
Something went wrong with that request. Please try again.