Chat packet handled in the new way; fixed missing packet sending for inventory slot.

Again, API change! cPlugin:OnChat() has had its parameters swapped, to match all the other callbacks - Player first, Message second

git-svn-id: http://mc-server.googlecode.com/svn/trunk@751 0a769ca7-a7f5-676a-18bf-c427514a06d6
master
madmaxoft@gmail.com 2012-08-18 10:38:15 +00:00
parent 2691e8daed
commit 1b5eaa92b5
18 changed files with 213 additions and 210 deletions

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 08/18/12 11:57:21.
** Generated automatically by tolua++-1.0.92 on 08/18/12 12:40:25.
*/
#ifndef __cplusplus
@ -7715,8 +7715,8 @@ static int tolua_AllToLua_cPlugin_OnChat00(lua_State* tolua_S)
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cPlugin",0,&tolua_err) ||
!tolua_isstring(tolua_S,2,0,&tolua_err) ||
!tolua_isusertype(tolua_S,3,"cPlayer",0,&tolua_err) ||
!tolua_isusertype(tolua_S,2,"cPlayer",0,&tolua_err) ||
!tolua_iscppstring(tolua_S,3,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,4,&tolua_err)
)
goto tolua_lerror;
@ -7724,17 +7724,18 @@ static int tolua_AllToLua_cPlugin_OnChat00(lua_State* tolua_S)
#endif
{
cPlugin* self = (cPlugin*) tolua_tousertype(tolua_S,1,0);
const char* a_Chat = ((const char*) tolua_tostring(tolua_S,2,0));
cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,3,0));
cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,2,0));
const AString a_Message = ((const AString) tolua_tocppstring(tolua_S,3,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'OnChat'", NULL);
#endif
{
bool tolua_ret = (bool) self->OnChat(a_Chat,a_Player);
bool tolua_ret = (bool) self->OnChat(a_Player,a_Message);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
tolua_pushcppstring(tolua_S,(const char*)a_Message);
}
}
return 1;
return 2;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'OnChat'.",&tolua_err);
@ -8697,16 +8698,16 @@ public:
return ( bool ) cPlugin:: OnBlockToPickup(a_BlockType,a_BlockMeta,a_Player,a_EquippedItem,a_Pickups);
};
};
bool OnChat( const char* a_Chat, cPlayer* a_Player) {
bool OnChat( cPlayer* a_Player, const AString& a_Message) {
if (push_method("OnChat", tolua_AllToLua_cPlugin_OnChat00)) {
tolua_pushstring(lua_state, (const char*)a_Chat);
tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
tolua_pushcppstring(lua_state, (const char*)a_Message);
ToluaBase::dbcall(lua_state, 3, 1);
bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
lua_pop(lua_state, 1);
return tolua_ret;
} else {
return ( bool ) cPlugin:: OnChat(a_Chat,a_Player);
return ( bool ) cPlugin:: OnChat(a_Player,a_Message);
};
};
void OnChunkGenerated( cWorld* a_World, int a_ChunkX, int a_ChunkZ) {
@ -8920,8 +8921,8 @@ public:
bool cPlugin__OnBlockToPickup( unsigned char a_BlockType, unsigned char a_BlockMeta, const cPlayer* a_Player, const cItem& a_EquippedItem, cItems& a_Pickups) {
return ( bool )cPlugin::OnBlockToPickup(a_BlockType,a_BlockMeta,a_Player,a_EquippedItem,a_Pickups);
};
bool cPlugin__OnChat( const char* a_Chat, cPlayer* a_Player) {
return ( bool )cPlugin::OnChat(a_Chat,a_Player);
bool cPlugin__OnChat( cPlayer* a_Player, const AString& a_Message) {
return ( bool )cPlugin::OnChat(a_Player,a_Message);
};
void cPlugin__OnChunkGenerated( cWorld* a_World, int a_ChunkX, int a_ChunkZ) {
return ( void )cPlugin::OnChunkGenerated(a_World,a_ChunkX,a_ChunkZ);
@ -9213,8 +9214,8 @@ static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnChat00(lua_State* tolua_S)
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"Lua__cPlugin",0,&tolua_err) ||
!tolua_isstring(tolua_S,2,0,&tolua_err) ||
!tolua_isusertype(tolua_S,3,"cPlayer",0,&tolua_err) ||
!tolua_isusertype(tolua_S,2,"cPlayer",0,&tolua_err) ||
!tolua_iscppstring(tolua_S,3,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,4,&tolua_err)
)
goto tolua_lerror;
@ -9222,17 +9223,18 @@ static int tolua_AllToLua_Lua__cPlugin_cPlugin__OnChat00(lua_State* tolua_S)
#endif
{
Lua__cPlugin* self = (Lua__cPlugin*) tolua_tousertype(tolua_S,1,0);
const char* a_Chat = ((const char*) tolua_tostring(tolua_S,2,0));
cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,3,0));
cPlayer* a_Player = ((cPlayer*) tolua_tousertype(tolua_S,2,0));
const AString a_Message = ((const AString) tolua_tocppstring(tolua_S,3,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'cPlugin__OnChat'", NULL);
#endif
{
bool tolua_ret = (bool) self->cPlugin__OnChat(a_Chat,a_Player);
bool tolua_ret = (bool) self->cPlugin__OnChat(a_Player,a_Message);
tolua_pushboolean(tolua_S,(bool)tolua_ret);
tolua_pushcppstring(tolua_S,(const char*)a_Message);
}
}
return 1;
return 2;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'cPlugin__OnChat'.",&tolua_err);
@ -10156,16 +10158,16 @@ public:
return ( bool ) cPlugin_NewLua:: OnBlockToPickup(a_BlockType,a_BlockMeta,a_Player,a_EquippedItem,a_Pickups);
};
};
bool OnChat( const char* a_Chat, cPlayer* a_Player) {
bool OnChat( cPlayer* a_Player, const AString& a_Message) {
if (push_method("OnChat", tolua_AllToLua_cPlugin_OnChat00)) {
tolua_pushstring(lua_state, (const char*)a_Chat);
tolua_pushusertype(lua_state, (void*)a_Player, "cPlayer");
tolua_pushcppstring(lua_state, (const char*)a_Message);
ToluaBase::dbcall(lua_state, 3, 1);
bool tolua_ret = ( bool )tolua_toboolean(lua_state, -1, 0);
lua_pop(lua_state, 1);
return tolua_ret;
} else {
return ( bool ) cPlugin_NewLua:: OnChat(a_Chat,a_Player);
return ( bool ) cPlugin_NewLua:: OnChat(a_Player,a_Message);
};
};
void OnChunkGenerated( cWorld* a_World, int a_ChunkX, int a_ChunkZ) {
@ -10382,8 +10384,8 @@ public:
bool cPlugin_NewLua__OnBlockToPickup( unsigned char a_BlockType, unsigned char a_BlockMeta, const cPlayer* a_Player, const cItem& a_EquippedItem, cItems& a_Pickups) {
return ( bool )cPlugin_NewLua::OnBlockToPickup(a_BlockType,a_BlockMeta,a_Player,a_EquippedItem,a_Pickups);
};
bool cPlugin_NewLua__OnChat( const char* a_Chat, cPlayer* a_Player) {
return ( bool )cPlugin_NewLua::OnChat(a_Chat,a_Player);
bool cPlugin_NewLua__OnChat( cPlayer* a_Player, const AString& a_Message) {
return ( bool )cPlugin_NewLua::OnChat(a_Player,a_Message);
};
void cPlugin_NewLua__OnChunkGenerated( cWorld* a_World, int a_ChunkX, int a_ChunkZ) {
return ( void )cPlugin_NewLua::OnChunkGenerated(a_World,a_ChunkX,a_ChunkZ);
@ -10632,7 +10634,7 @@ static int tolua_AllToLua_cServer_ServerCommand00(lua_State* tolua_S)
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cServer",0,&tolua_err) ||
!tolua_isstring(tolua_S,2,0,&tolua_err) ||
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
@ -10640,15 +10642,16 @@ static int tolua_AllToLua_cServer_ServerCommand00(lua_State* tolua_S)
#endif
{
cServer* self = (cServer*) tolua_tousertype(tolua_S,1,0);
const char* a_Cmd = ((const char*) tolua_tostring(tolua_S,2,0));
const AString a_Cmd = ((const AString) tolua_tocppstring(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'ServerCommand'", NULL);
#endif
{
self->ServerCommand(a_Cmd);
tolua_pushcppstring(tolua_S,(const char*)a_Cmd);
}
}
return 0;
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'ServerCommand'.",&tolua_err);
@ -14546,7 +14549,7 @@ static int tolua_AllToLua_cRoot_ServerCommand00(lua_State* tolua_S)
tolua_Error tolua_err;
if (
!tolua_isusertype(tolua_S,1,"cRoot",0,&tolua_err) ||
!tolua_isstring(tolua_S,2,0,&tolua_err) ||
!tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
!tolua_isnoobj(tolua_S,3,&tolua_err)
)
goto tolua_lerror;
@ -14554,15 +14557,16 @@ static int tolua_AllToLua_cRoot_ServerCommand00(lua_State* tolua_S)
#endif
{
cRoot* self = (cRoot*) tolua_tousertype(tolua_S,1,0);
const char* a_Cmd = ((const char*) tolua_tostring(tolua_S,2,0));
const AString a_Cmd = ((const AString) tolua_tocppstring(tolua_S,2,0));
#ifndef TOLUA_RELEASE
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'ServerCommand'", NULL);
#endif
{
self->ServerCommand(a_Cmd);
tolua_pushcppstring(tolua_S,(const char*)a_Cmd);
}
}
return 0;
return 1;
#ifndef TOLUA_RELEASE
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'ServerCommand'.",&tolua_err);

View File

@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
** Generated automatically by tolua++-1.0.92 on 08/18/12 11:57:21.
** Generated automatically by tolua++-1.0.92 on 08/18/12 12:40:25.
*/
/* Exported function */

View File

@ -634,8 +634,12 @@ void cClientHandle::HandlePacket(cPacket * a_Packet)
HandleBlockPlace(bp->m_PosX, bp->m_PosY, bp->m_PosZ, bp->m_Direction, bp->m_HeldItem);
break;
}
case E_PICKUP_SPAWN: HandlePickupSpawn (reinterpret_cast<cPacket_PickupSpawn *> (a_Packet)); break;
case E_CHAT: HandleChat (reinterpret_cast<cPacket_Chat *> (a_Packet)); break;
case E_CHAT:
{
cPacket_Chat * ch = reinterpret_cast<cPacket_Chat *>(a_Packet);
HandleChat(ch->m_Message);
break;
}
case E_PLAYERLOOK: HandlePlayerLook (reinterpret_cast<cPacket_PlayerLook *> (a_Packet)); break;
case E_PLAYERMOVELOOK: HandlePlayerMoveLook (reinterpret_cast<cPacket_PlayerMoveLook *> (a_Packet)); break;
case E_ANIMATION: HandleAnimation (reinterpret_cast<cPacket_ArmAnim *> (a_Packet)); break;
@ -1022,31 +1026,18 @@ void cClientHandle::HandleBlockPlace(int a_BlockX, int a_BlockY, int a_BlockZ, c
void cClientHandle::HandlePickupSpawn(cPacket_PickupSpawn * a_Packet)
void cClientHandle::HandleChat(const AString & a_Message)
{
LOG("Received packet E_PICKUP_SPAWN");
cItem DroppedItem;
DroppedItem.m_ItemID = (ENUM_ITEM_ID)a_Packet->m_Item;
DroppedItem.m_ItemCount = a_Packet->m_Count;
DroppedItem.m_ItemHealth = 0x0; // TODO: Somehow figure out what item was dropped, and apply correct health
if (m_Player->GetInventory().RemoveItem(DroppedItem))
if (!cRoot::Get()->GetServer()->Command(*this, a_Message))
{
cPickup * Pickup = new cPickup(a_Packet);
Pickup->Initialize(m_Player->GetWorld());
}
}
void cClientHandle::HandleChat(cPacket_Chat * a_Packet)
{
if (!cRoot::Get()->GetServer()->Command(*this, a_Packet->m_Message.c_str()))
{
a_Packet->m_Message.insert(0, "<" + m_Player->GetColor() + m_Username + cChatColor::White + "> ");
cRoot::Get()->GetServer()->Broadcast(*a_Packet);
AString Msg;
Printf(Msg, "<%s%s%s> %s",
m_Player->GetColor().c_str(),
m_Player->GetName().c_str(),
cChatColor::White.c_str(),
a_Message.c_str()
);
m_Player->GetWorld()->BroadcastChat(Msg);
}
}
@ -1443,6 +1434,17 @@ void cClientHandle::SendInventorySlot(int a_WindowID, short a_SlotNum, const cIt
Packet.m_ItemID = (short)(a_Item.m_ItemID);
Packet.m_ItemCount = a_Item.m_ItemCount;
Packet.m_ItemUses = a_Item.m_ItemHealth;
Send(Packet);
}
void cClientHandle::SendChat(const AString & a_Message)
{
cPacket_Chat Chat(a_Message);
Send(Chat);
}

View File

@ -105,6 +105,7 @@ public:
void SendDisconnect(const AString & a_Reason);
void SendHandshake (const AString & a_ServerName);
void SendInventorySlot(int a_WindowID, short a_SlotNum, const cItem & a_Item);
void SendChat(const AString & a_Message);
const AString & GetUsername(void) const; //tolua_export
@ -196,8 +197,7 @@ private:
void HandlePlayerPos (double a_PosX, double a_PosY, double a_PosZ, double a_Stance, bool a_IsOnGround);
void HandleBlockDig (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status);
void HandleBlockPlace (int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, const cItem & a_HeldItem);
void HandlePickupSpawn (cPacket_PickupSpawn * a_Packet);
void HandleChat (cPacket_Chat * a_Packet);
void HandleChat (const AString & a_Message);
void HandlePlayerLook (cPacket_PlayerLook * a_Packet);
void HandlePlayerMoveLook (cPacket_PlayerMoveLook * a_Packet); // While m_bPositionConfirmed (normal gameplay)
void HandleAnimation (cPacket_ArmAnim * a_Packet);

View File

@ -83,10 +83,10 @@ bool cPlugin::OnBlockToPickup(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, con
bool cPlugin::OnChat(const char * a_Chat, cPlayer * a_Player)
bool cPlugin::OnChat(cPlayer * a_Player, const AString & a_Message)
{
UNUSED(a_Chat);
UNUSED(a_Player);
UNUSED(a_Message);
return false;
}

View File

@ -51,7 +51,7 @@ public:
virtual bool OnBlockDig (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta);
virtual bool OnBlockPlace (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, const cItem & a_HeldItem);
virtual bool OnBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups);
virtual bool OnChat (const char * a_Chat, cPlayer * a_Player );
virtual bool OnChat (cPlayer * a_Player, const AString & a_Message);
virtual void OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ);
virtual bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk);
virtual bool OnCollectItem (cPickup* a_Pickup, cPlayer* a_Player );

View File

@ -191,55 +191,6 @@ bool cPluginManager::CallHook(PluginHook a_Hook, unsigned int a_NumArgs, ...)
{
HookMap::iterator Plugins = m_Hooks.find( a_Hook );
// Special case for chat hook, since you can also bind commands (bound commands don't use chat hook)
if (a_Hook == HOOK_CHAT)
{
if (a_NumArgs != 2)
{
return false;
}
va_list argptr;
va_start( argptr, a_NumArgs);
const char * Message = va_arg(argptr, const char* );
cPlayer * Player = va_arg(argptr, cPlayer * );
va_end (argptr);
#ifdef USE_SQUIRREL
if (m_SquirrelCommandBinder->HandleCommand( std::string( Message ), Player))
{
return true;
}
#endif
if (m_LuaCommandBinder->HandleCommand( std::string( Message ), Player))
{
return true;
}
//Check if it was a standard command (starts with a slash)
if(Message[0] == '/')
{
Player->SendMessage("Unknown Command");
LOGINFO("Player \"%s\" issued command: %s", Player->GetName().c_str(), Message);
return true; //Cancel sending
}
if (Plugins == m_Hooks.end())
{
return false;
}
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
{
if ((*itr)->OnChat(Message, Player))
{
return true;
}
}
return false;
}
if (Plugins == m_Hooks.end())
{
return false;
@ -452,6 +403,49 @@ bool cPluginManager::CallHookBlockPlace(cPlayer * a_Player, int a_BlockX, int a_
bool cPluginManager::CallHookChat(cPlayer * a_Player, const AString & a_Message)
{
#ifdef USE_SQUIRREL
if (m_SquirrelCommandBinder->HandleCommand(a_Message, a_Player))
{
return true;
}
#endif // USE_SQUIRREL
if (m_LuaCommandBinder->HandleCommand(a_Message, a_Player))
{
return true;
}
//Check if it was a standard command (starts with a slash)
if (a_Message[0] == '/')
{
a_Player->SendMessage("Unknown Command");
LOGINFO("Player \"%s\" issued an unknown command: \"%s\"", a_Player->GetName().c_str(), a_Message.c_str());
return true; // Cancel sending
}
HookMap::iterator Plugins = m_Hooks.find(HOOK_CHAT);
if (Plugins == m_Hooks.end())
{
return false;
}
for (PluginList::iterator itr = Plugins->second.begin(); itr != Plugins->second.end(); ++itr)
{
if ((*itr)->OnChat(a_Player, a_Message))
{
return true;
}
}
return false;
}
bool cPluginManager::CallHookChunkGenerating(cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_LuaChunk)
{
HookMap::iterator Plugins = m_Hooks.find(HOOK_CHUNK_GENERATING);

View File

@ -97,17 +97,18 @@ public: //tolua_export
// If the hook returns true, no further hook is called and the functions return false
bool CallHook( PluginHook a_Hook, unsigned int a_NumArgs, ... );
bool CallHookLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username);
bool CallHookBlockDig (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status, BLOCKTYPE OldBlock, NIBBLETYPE OldMeta);
bool CallHookBlockPlace (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, const cItem & a_HeldItem);
bool CallHookChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_Chunk);
bool CallHookPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
bool CallHookCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
bool CallHookPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
bool CallHookBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups);
bool CallHookWeatherChanged (cWorld * a_World);
bool CallHookUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4);
bool CallHookChat (cPlayer * a_Player, const AString & a_Message);
bool CallHookChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_Chunk);
bool CallHookCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
bool CallHookLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username);
bool CallHookPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
bool CallHookPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe);
bool CallHookUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
bool CallHookUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4);
bool CallHookWeatherChanged (cWorld * a_World);
void RemoveHooks( cPlugin* a_Plugin );
void RemovePlugin( cPlugin* a_Plugin, bool a_bDelete = false ); //tolua_export

View File

@ -260,20 +260,23 @@ bool cPlugin_NewLua::OnBlockDig(cPlayer * a_Player, int a_BlockX, int a_BlockY,
bool cPlugin_NewLua::OnChat( const char* a_Chat, cPlayer* a_Player )
bool cPlugin_NewLua::OnChat(cPlayer * a_Player, const AString & a_Message)
{
cCSLock Lock( m_CriticalSection );
if( !PushFunction("OnChat") )
cCSLock Lock(m_CriticalSection);
if (!PushFunction("OnChat"))
{
return false;
}
tolua_pushstring( m_LuaState, a_Chat );
tolua_pushusertype(m_LuaState, a_Player, "cPlayer");
tolua_pushstring (m_LuaState, a_Message.c_str());
if( !CallFunction(2, 1, "OnChat") )
if (!CallFunction(2, 1, "OnChat"))
{
return false;
}
bool bRetVal = (tolua_toboolean( m_LuaState, -1, 0) > 0);
return bRetVal;
return (tolua_toboolean( m_LuaState, -1, 0) > 0);
}

View File

@ -25,26 +25,26 @@ public: //tolua_export
virtual void Tick(float a_Dt); //tolua_export
virtual bool OnCollectItem (cPickup* a_Pickup, cPlayer* a_Player ) override;
virtual bool OnDisconnect (const AString & a_Reason, cPlayer * a_Player ) override;
virtual bool OnBlockPlace (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, const cItem & a_HeldItem) override;
virtual bool OnBlockDig (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta) override;
virtual bool OnChat (const char* a_Chat, cPlayer* a_Player ) override;
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) override;
virtual void OnPlayerSpawn (cPlayer* a_Player ) override;
virtual bool OnPlayerJoin (cPlayer* a_Player ) override;
virtual void OnPlayerMove (cPlayer* a_Player ) override;
virtual void OnTakeDamage (cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) override;
virtual bool OnKilled (cPawn* a_Killed, cEntity* a_Killer ) override;
virtual bool OnBlockPlace (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, const cItem & a_HeldItem) override;
virtual bool OnBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups);
virtual bool OnChat (cPlayer * a_Player, const AString & a_Message) override;
virtual void OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override;
virtual bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk ) override;
virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual bool OnCollectItem (cPickup* a_Pickup, cPlayer* a_Player ) override;
virtual bool OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual bool OnDisconnect (const AString & a_Reason, cPlayer * a_Player ) override;
virtual bool OnKilled (cPawn* a_Killed, cEntity* a_Killer ) override;
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) override;
virtual bool OnPlayerJoin (cPlayer* a_Player ) override;
virtual void OnPlayerMove (cPlayer* a_Player ) override;
virtual void OnPlayerSpawn (cPlayer* a_Player ) override;
virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual bool OnBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups);
virtual bool OnWeatherChanged (cWorld * a_World) override;
virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) override;
virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual void OnTakeDamage (cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) override;
virtual bool OnUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override;
virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) override;
virtual bool OnWeatherChanged (cWorld * a_World) override;
lua_State* GetLuaState() { return m_LuaState; }

View File

@ -151,13 +151,13 @@ bool cPlugin_Squirrel::OnBlockDig(cPlayer * a_Player, int a_BlockX, int a_BlockY
bool cPlugin_Squirrel::OnChat(const char * a_Chat, cPlayer * a_Player)
bool cPlugin_Squirrel::OnChat(cPlayer * a_Player, const AString & a_Message)
{
cCSLock Lock( m_CriticalSection );
cCSLock Lock(m_CriticalSection);
if (!m_Plugin->HasFunction("OnChat")) return false;
return m_Plugin->GetFunction("OnChat").Evaluate<bool>(a_Chat, a_Player);
return m_Plugin->GetFunction("OnChat").Evaluate<bool>(a_Player, a_Message);
}

View File

@ -14,26 +14,26 @@ public:
void Tick(float a_Dt);
bool OnCollectItem (cPickup* a_Pickup, cPlayer* a_Player ) override;
bool OnDisconnect (const AString & a_Reason, cPlayer * a_Player ) override;
bool OnBlockPlace (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, const cItem & a_HeldItem) override;
bool OnBlockDig (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta) override;
bool OnChat (const char * a_Chat, cPlayer * a_Player ) override;
bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) override;
void OnPlayerSpawn (cPlayer* a_Player ) override;
bool OnPlayerJoin (cPlayer* a_Player ) override;
void OnPlayerMove (cPlayer* a_Player ) override;
void OnTakeDamage (cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) override;
bool OnKilled (cPawn* a_Killed, cEntity* a_Killer ) override;
void OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override;
bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk ) override;
bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
bool OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
bool OnBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups);
bool OnWeatherChanged (cWorld * a_World) override;
bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) override;
bool OnUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override;
virtual bool OnBlockDig (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, char a_Status, BLOCKTYPE a_OldBlock, NIBBLETYPE a_OldMeta) override;
virtual bool OnBlockPlace (cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, char a_BlockFace, const cItem & a_HeldItem) override;
virtual bool OnBlockToPickup (BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, const cPlayer * a_Player, const cItem & a_EquippedItem, cItems & a_Pickups);
virtual bool OnChat (cPlayer * a_Player, const AString & a_Message) override;
virtual void OnChunkGenerated (cWorld * a_World, int a_ChunkX, int a_ChunkZ) override;
virtual bool OnChunkGenerating (cWorld * a_World, int a_ChunkX, int a_ChunkZ, cLuaChunk * a_pLuaChunk ) override;
virtual bool OnCollectItem (cPickup* a_Pickup, cPlayer* a_Player ) override;
virtual bool OnCraftingNoRecipe(const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual bool OnDisconnect (const AString & a_Reason, cPlayer * a_Player ) override;
virtual bool OnKilled (cPawn* a_Killed, cEntity* a_Killer ) override;
virtual bool OnLogin (cClientHandle * a_Client, int a_ProtocolVersion, const AString & a_Username) override;
virtual bool OnPlayerJoin (cPlayer* a_Player ) override;
virtual void OnPlayerMove (cPlayer* a_Player ) override;
virtual void OnPlayerSpawn (cPlayer* a_Player ) override;
virtual bool OnPostCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual bool OnPreCrafting (const cPlayer * a_Player, const cCraftingGrid * a_Grid, cCraftingRecipe * a_Recipe) override;
virtual void OnTakeDamage (cPawn* a_Pawn, TakeDamageInfo* a_TakeDamageInfo ) override;
virtual bool OnUpdatedSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4) override;
virtual bool OnUpdatingSign (cWorld * a_World, int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4) override;
virtual bool OnWeatherChanged (cWorld * a_World) override;
protected:
const char * m_PluginName;

View File

@ -75,18 +75,18 @@ cRoot::~cRoot()
void cRoot::InputThread(void* a_Params)
void cRoot::InputThread(void * a_Params)
{
#if defined(ANDROID_NDK)
return;
#else
cRoot& self = *(cRoot*)a_Params;
cRoot & self = *(cRoot*)a_Params;
while( !(self.m_bStop || self.m_bRestart) )
while (!(self.m_bStop || self.m_bRestart))
{
std::string Command;
std::getline(std::cin, Command);
self.ServerCommand( Command.c_str() );
self.ServerCommand(Command);
}
#endif
}
@ -351,15 +351,15 @@ void cRoot::TickWorlds( float a_Dt )
void cRoot::ServerCommand( const char * a_Cmd )
void cRoot::ServerCommand(const AString & a_Cmd)
{
LOG("Server console command: \"%s\"", a_Cmd );
m_Server->ServerCommand( a_Cmd );
if( strcmp(a_Cmd, "stop") == 0 )
LOG("Server console command: \"%s\"", a_Cmd.c_str());
m_Server->ServerCommand(a_Cmd);
if (a_Cmd == "stop")
{
m_bStop = true;
}
else if( strcmp( a_Cmd, "restart") == 0 )
else if (a_Cmd == "restart")
{
m_bRestart = true;
}

View File

@ -56,7 +56,7 @@ public:
cPluginManager * GetPluginManager (void) { return m_PluginManager; } // tolua_export
cAuthenticator & GetAuthenticator (void) { return m_Authenticator; }
void ServerCommand(const char* a_Cmd ); //tolua_export
void ServerCommand(const AString & a_Cmd); //tolua_export
void KickUser(int a_ClientID, const AString & a_Reason); // Kicks the user, no matter in what world they are. Used from cAuthenticator
void AuthenticateUser(int a_ClientID); // Called by cAuthenticator to auth the specified user

View File

@ -437,45 +437,24 @@ void cServer::StartListenThread()
template <class T>
bool from_string(
T& t,
const std::string& s,
std::ios_base& (*f)(std::ios_base&)
)
bool cServer::Command(cClientHandle & a_Client, const AString & a_Cmd)
{
std::istringstream iss(s);
return !(iss >> f >> t).fail();
return cRoot::Get()->GetPluginManager()->CallHookChat(a_Client.GetPlayer(), a_Cmd);
}
bool cServer::Command( cClientHandle & a_Client, const char* a_Cmd )
void cServer::ServerCommand(const AString & a_Cmd)
{
cPluginManager* PM = cRoot::Get()->GetPluginManager();
if( PM->CallHook( cPluginManager::E_PLUGIN_CHAT, 2, a_Cmd, a_Client.GetPlayer() ) )
{
return true;
}
return false;
}
void cServer::ServerCommand( const char * a_Cmd )
{
AString Command( a_Cmd );
AStringVector split = StringSplit( Command, " " );
if( split.empty())
AStringVector split = StringSplit(a_Cmd, " ");
if (split.empty())
{
return;
}
if( split[0].compare( "help" ) == 0 )
if (split[0].compare( "help" ) == 0)
{
printf("================== ALL COMMANDS ===================\n");
printf("help - Shows this message\n");
@ -491,11 +470,11 @@ void cServer::ServerCommand( const char * a_Cmd )
printf("===================================================\n");
return;
}
if( split[0].compare( "stop" ) == 0 || split[0].compare( "restart" ) == 0 )
if ((split[0].compare("stop") == 0) || (split[0].compare("restart") == 0))
{
return;
}
if( split[0].compare( "save-all" ) == 0 )
if (split[0].compare("save-all") == 0)
{
cRoot::Get()->SaveAllChunks();
return;
@ -507,7 +486,7 @@ void cServer::ServerCommand( const char * a_Cmd )
LOG("Num loaded chunks after: %i", cRoot::Get()->GetTotalChunkCount() );
return;
}
if( split[0].compare( "list" ) == 0 )
if (split[0].compare("list") == 0)
{
class cPlayerLogger : public cPlayerListCallback
{
@ -520,7 +499,7 @@ void cServer::ServerCommand( const char * a_Cmd )
cRoot::Get()->ForEachPlayer(Logger);
return;
}
if( split[0].compare( "numchunks" ) == 0 )
if (split[0].compare("numchunks") == 0)
{
LOG("Num loaded chunks: %i", cRoot::Get()->GetTotalChunkCount() );
return;
@ -531,19 +510,19 @@ void cServer::ServerCommand( const char * a_Cmd )
return;
}
if(split[0].compare("monsters") == 0 )
if (split[0].compare("monsters") == 0)
{
// TODO: cWorld::ListMonsters();
return;
}
if(split.size() > 1)
if (split.size() > 1)
{
if( split[0].compare( "say" ) == 0 )
if (split[0].compare("say") == 0)
{
std::string Message = cChatColor::Purple + "[SERVER] " + Command.substr( Command.find_first_of("say") + 4 );
AString Message = cChatColor::Purple + "[SERVER] " + a_Cmd.substr(a_Cmd.find_first_of("say") + 4);
LOG("%s", Message.c_str() );
Broadcast( cPacket_Chat(Message) );
Broadcast(cPacket_Chat(Message));
return;
}
}

View File

@ -44,8 +44,8 @@ public: //tolua_export
void StartListenThread();
bool Command( cClientHandle & a_Client, const char* a_Cmd );
void ServerCommand( const char* a_Cmd ); //tolua_export
bool Command(cClientHandle & a_Client, const AString & a_Cmd);
void ServerCommand(const AString & a_Cmd); //tolua_export
void Shutdown();
void SendMessage( const char* a_Message, cPlayer* a_Player = 0, bool a_bExclude = false ); //tolua_export

View File

@ -1238,7 +1238,7 @@ void cWorld::Broadcast( const cPacket & a_Packet, cClientHandle * a_Exclude)
{
continue;
}
(*itr)->GetClientHandle()->Send( a_Packet );
ch->Send( a_Packet );
}
}
@ -1264,6 +1264,24 @@ void cWorld::BroadcastToChunkOfBlock(int a_X, int a_Y, int a_Z, cPacket * a_Pack
void cWorld::BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude)
{
cCSLock Lock(m_CSPlayers);
for (cPlayerList::iterator itr = m_Players.begin(); itr != m_Players.end(); ++itr)
{
cClientHandle * ch = (*itr)->GetClientHandle();
if ((ch == a_Exclude) || (ch == NULL) || !ch->IsLoggedIn() || ch->IsDestroyed())
{
continue;
}
ch->SendChat(a_Message);
}
}
void cWorld::MarkChunkDirty (int a_ChunkX, int a_ChunkY, int a_ChunkZ)
{
m_ChunkMap->MarkChunkDirty (a_ChunkX, a_ChunkY, a_ChunkZ);

View File

@ -74,10 +74,12 @@ public:
int GetHeight( int a_X, int a_Z ); //tolua_export
void Broadcast( const cPacket & a_Packet, cClientHandle* a_Exclude = 0 );
void Broadcast(const cPacket & a_Packet, cClientHandle * a_Exclude = NULL);
void BroadcastToChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, const cPacket & a_Packet, cClientHandle * a_Exclude = NULL);
void BroadcastToChunkOfBlock(int a_X, int a_Y, int a_Z, cPacket * a_Packet, cClientHandle * a_Exclude = NULL);
void BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude = NULL);
void MarkChunkDirty (int a_ChunkX, int a_ChunkY, int a_ChunkZ);
void MarkChunkSaving(int a_ChunkX, int a_ChunkY, int a_ChunkZ);
void MarkChunkSaved (int a_ChunkX, int a_ChunkY, int a_ChunkZ);