diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-24 09:58:26 +0200 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2012-08-24 09:58:26 +0200 |
commit | e92b9e7ecbdf2918aab59d4eeb7bb5966430b264 (patch) | |
tree | 1a998d44e5faab91c54ea8517dd9fa02b3732ef7 /source/cServer.cpp | |
parent | Added plugin name to deprecation messages (diff) | |
download | cuberite-e92b9e7ecbdf2918aab59d4eeb7bb5966430b264.tar cuberite-e92b9e7ecbdf2918aab59d4eeb7bb5966430b264.tar.gz cuberite-e92b9e7ecbdf2918aab59d4eeb7bb5966430b264.tar.bz2 cuberite-e92b9e7ecbdf2918aab59d4eeb7bb5966430b264.tar.lz cuberite-e92b9e7ecbdf2918aab59d4eeb7bb5966430b264.tar.xz cuberite-e92b9e7ecbdf2918aab59d4eeb7bb5966430b264.tar.zst cuberite-e92b9e7ecbdf2918aab59d4eeb7bb5966430b264.zip |
Diffstat (limited to 'source/cServer.cpp')
-rw-r--r-- | source/cServer.cpp | 46 |
1 files changed, 32 insertions, 14 deletions
diff --git a/source/cServer.cpp b/source/cServer.cpp index ef626614a..162512f24 100644 --- a/source/cServer.cpp +++ b/source/cServer.cpp @@ -27,8 +27,6 @@ #include "../iniFile/iniFile.h" #include "Vector3f.h" -#include "packets/cPacket_Chat.h" - #include <fstream> #include <sstream> #include <iostream> @@ -286,16 +284,33 @@ cServer::~cServer() // TODO - Need to modify this or something, so it broadcasts to all worlds? And move this to cWorld? -void cServer::Broadcast( const cPacket & a_Packet, cClientHandle* a_Exclude /* = 0 */ ) +void cServer::Broadcast(const cPacket & a_Packet, cClientHandle * a_Exclude) { cCSLock Lock(m_CSClients); - for( ClientList::iterator itr = m_Clients.begin(); itr != m_Clients.end(); ++itr) + for (ClientList::iterator itr = m_Clients.begin(); itr != m_Clients.end(); ++itr) { if ((*itr == a_Exclude) || !(*itr)->IsLoggedIn()) { continue; } - (*itr)->Send( a_Packet ); + (*itr)->Send(a_Packet); + } +} + + + + + +void cServer::BroadcastChat(const AString & a_Message, const cClientHandle * a_Exclude) +{ + cCSLock Lock(m_CSClients); + for (ClientList::iterator itr = m_Clients.begin(); itr != m_Clients.end(); ++itr) + { + if ((*itr == a_Exclude) || !(*itr)->IsLoggedIn()) + { + continue; + } + (*itr)->SendChat(a_Message); } } @@ -520,9 +535,10 @@ void cServer::ServerCommand(const AString & a_Cmd) { if (split[0].compare("say") == 0) { - AString Message = cChatColor::Purple + "[SERVER] " + a_Cmd.substr(a_Cmd.find_first_of("say") + 4); - LOG("%s", Message.c_str() ); - Broadcast(cPacket_Chat(Message)); + AString ToSay = a_Cmd.substr(a_Cmd.find_first_of("say") + 4); + AString Message = cChatColor::Purple + "[SERVER] " + ToSay; + LOG("[SERVER]: %s", ToSay.c_str()); + BroadcastChat(Message); return; } } @@ -534,17 +550,19 @@ void cServer::ServerCommand(const AString & a_Cmd) -void cServer::SendMessage( const char* a_Message, cPlayer* a_Player /* = 0 */, bool a_bExclude /* = false */ ) +void cServer::SendMessage(const AString & a_Message, cPlayer * a_Player /* = NULL */, bool a_bExclude /* = false */ ) { - cPacket_Chat Chat( a_Message ); - if( a_Player && !a_bExclude ) + if ((a_Player != NULL) && !a_bExclude) { - cClientHandle* Client = a_Player->GetClientHandle(); - if( Client ) Client->Send( Chat ); + cClientHandle * Client = a_Player->GetClientHandle(); + if (Client != NULL) + { + Client->SendChat(a_Message); + } return; } - Broadcast( Chat, (a_Player)?a_Player->GetClientHandle():0 ); + BroadcastChat(a_Message, (a_Player != NULL) ? a_Player->GetClientHandle() : NULL); } |