summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authormtilden@gmail.com <mtilden@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-12-26 02:07:35 +0100
committermtilden@gmail.com <mtilden@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6>2011-12-26 02:07:35 +0100
commitbf838238e45f4ba96c0653f77cf1bf79e6c13c78 (patch)
tree12a75a20b00d825c45f846f8e11f7ace9144906b /source
parent- Fixed Bug #99 -> Mobs no longer bother you in creative mode (diff)
downloadcuberite-bf838238e45f4ba96c0653f77cf1bf79e6c13c78.tar
cuberite-bf838238e45f4ba96c0653f77cf1bf79e6c13c78.tar.gz
cuberite-bf838238e45f4ba96c0653f77cf1bf79e6c13c78.tar.bz2
cuberite-bf838238e45f4ba96c0653f77cf1bf79e6c13c78.tar.lz
cuberite-bf838238e45f4ba96c0653f77cf1bf79e6c13c78.tar.xz
cuberite-bf838238e45f4ba96c0653f77cf1bf79e6c13c78.tar.zst
cuberite-bf838238e45f4ba96c0653f77cf1bf79e6c13c78.zip
Diffstat (limited to 'source')
-rw-r--r--source/PacketID.h1
-rw-r--r--source/cChatColor.cpp2
-rw-r--r--source/cClientHandle.cpp11
-rw-r--r--source/cPlayer.cpp19
-rw-r--r--source/cPlayer.h2
-rw-r--r--source/packets/cPacket_PlayerListItem.cpp27
-rw-r--r--source/packets/cPacket_PlayerListItem.h21
-rw-r--r--source/packets/cPacket_WindowClose.h2
8 files changed, 80 insertions, 5 deletions
diff --git a/source/PacketID.h b/source/PacketID.h
index f19d7a795..7fc068b53 100644
--- a/source/PacketID.h
+++ b/source/PacketID.h
@@ -52,6 +52,7 @@ enum ENUM_PACKET_ID
E_INVENTORY_PROGRESS= 0x69,
E_CREATE_INVENTORY_ACTION = 0x6B,
E_UPDATE_SIGN = 0x82,
+ E_PLAYER_LIST_ITEM = 0xC9,
E_PING = 0xfe,
E_DISCONNECT = 0xff,
};
diff --git a/source/cChatColor.cpp b/source/cChatColor.cpp
index a0f7813c5..4f955dcb7 100644
--- a/source/cChatColor.cpp
+++ b/source/cChatColor.cpp
@@ -21,5 +21,5 @@ const std::string cChatColor::White = cChatColor::Color + "f";
const std::string cChatColor::MakeColor( char a_Color )
{
- return cChatColor::Color + a_Color;
+ return cChatColor::Delimiter + a_Color;
} \ No newline at end of file
diff --git a/source/cClientHandle.cpp b/source/cClientHandle.cpp
index 902e3df2f..c9d1de1ce 100644
--- a/source/cClientHandle.cpp
+++ b/source/cClientHandle.cpp
@@ -65,6 +65,7 @@
#include "packets/cPacket_13.h"
#include "packets/cPacket_UpdateSign.h"
#include "packets/cPacket_Ping.h"
+#include "packets/cPacket_PlayerListItem.h"
#ifndef _WIN32
@@ -155,6 +156,7 @@ cClientHandle::cClientHandle(const cSocket & a_Socket)
m_pState->PacketMap[E_UPDATE_SIGN] = new cPacket_UpdateSign;
m_pState->PacketMap[E_RESPAWN] = new cPacket_Respawn;
m_pState->PacketMap[E_PING] = new cPacket_Ping;
+ m_pState->PacketMap[E_PLAYER_LIST_ITEM] = new cPacket_PlayerListItem;
memset( m_LoadedChunks, 0x00, sizeof(cChunk*)*VIEWDISTANCE*VIEWDISTANCE );
@@ -1161,6 +1163,15 @@ void cClientHandle::HandlePacket( cPacket* a_Packet )
{
cPacket_Chat DisconnectMessage( m_pState->Username + " disconnected: " + PacketData->m_Reason );
cRoot::Get()->GetServer()->Broadcast( DisconnectMessage );
+ cWorld::PlayerList PlayerList = cRoot::Get()->GetWorld()->GetAllPlayers();
+ for( cWorld::PlayerList::iterator itr = PlayerList.begin(); itr != PlayerList.end(); ++itr )
+ {
+ cPacket_PlayerListItem PlayerList;
+ PlayerList.m_PlayerName = GetUsername();
+ PlayerList.m_Online = false;
+ PlayerList.m_Ping = (short)5;
+ (*itr)->GetClientHandle()->Send( PlayerList );
+ }
}
Destroy();
return;
diff --git a/source/cPlayer.cpp b/source/cPlayer.cpp
index d13e1e5aa..fd7a09a6b 100644
--- a/source/cPlayer.cpp
+++ b/source/cPlayer.cpp
@@ -29,6 +29,7 @@
#include "packets/cPacket_Metadata.h"
#include "packets/cPacket_Chat.h"
#include "packets/cPacket_NewInvalidState.h"
+#include "packets/cPacket_PlayerListItem.h"
#include "Vector3d.h"
#include "Vector3f.h"
@@ -232,6 +233,20 @@ void cPlayer::Tick(float a_Dt)
if(e_EPMetaState == BURNING){
InStateBurning(a_Dt);
}
+
+ // Send Player List
+ cWorld::PlayerList PlayerList = cRoot::Get()->GetWorld()->GetAllPlayers();
+ for( cWorld::PlayerList::iterator itr = PlayerList.begin(); itr != PlayerList.end(); ++itr )
+ {
+ if ((*itr) && (*itr)->GetClientHandle() && !((*itr)->GetClientHandle()->IsDestroyed())) {
+ cPacket_PlayerListItem PlayerList;
+ PlayerList.m_PlayerName = GetColor() + GetName();
+ PlayerList.m_Online = true;
+ PlayerList.m_Ping = (short)5;
+ (*itr)->GetClientHandle()->Send( PlayerList );
+ }
+ }
+
}
void cPlayer::InStateBurning(float a_Dt) {
@@ -406,10 +421,10 @@ void cPlayer::OpenWindow( cWindow* a_Window )
m_CurrentWindow = a_Window;
}
-void cPlayer::CloseWindow(char wID = -1)
+void cPlayer::CloseWindow(char a_WindowType)
{
if( m_CurrentWindow ) m_CurrentWindow->Close( *this );
- if (wID == 0) {
+ if (a_WindowType == 0) {
if(GetInventory().GetWindow()->GetDraggingItem() && GetInventory().GetWindow()->GetDraggingItem()->m_ItemCount > 0)
{
LOG("Player holds item! Dropping it...");
diff --git a/source/cPlayer.h b/source/cPlayer.h
index c8bd6c473..e25fb1b07 100644
--- a/source/cPlayer.h
+++ b/source/cPlayer.h
@@ -46,7 +46,7 @@ public:
cWindow* GetWindow() { return m_CurrentWindow; }
void OpenWindow( cWindow* a_Window );
- void CloseWindow(char wID);
+ void CloseWindow(char a_WindowType);
cClientHandle* GetClientHandle() { return m_ClientHandle; } //tolua_export
void SetClientHandle( cClientHandle* a_Client ) { m_ClientHandle = a_Client; }
diff --git a/source/packets/cPacket_PlayerListItem.cpp b/source/packets/cPacket_PlayerListItem.cpp
new file mode 100644
index 000000000..b0726dc8a
--- /dev/null
+++ b/source/packets/cPacket_PlayerListItem.cpp
@@ -0,0 +1,27 @@
+#include "cPacket_PlayerListItem.h"
+
+bool cPacket_PlayerListItem::Parse( cSocket & a_Socket )
+{
+ m_Socket = a_Socket;
+ if (!ReadString(m_PlayerName)) return false;
+ if (!ReadBool(m_Online)) return false;
+ if (!ReadShort(m_Ping)) return false;
+ return true;
+}
+
+bool cPacket_PlayerListItem::Send( cSocket & a_Socket )
+{
+ m_PlayerName = m_PlayerName.substr(0,16);
+ unsigned int TotalSize = c_Size + m_PlayerName.size()*sizeof(short);
+ char* Message = new char[TotalSize];
+
+ unsigned int i = 0;
+ AppendByte((char)m_PacketID, Message, i);
+ AppendString16(m_PlayerName, Message, i);
+ AppendBool(m_Online, Message, i);
+ AppendShort(m_Ping, Message, i);
+
+ bool RetVal = !cSocket::IsSocketError( SendData( a_Socket, Message, TotalSize, 0 ) );
+ delete [] Message;
+ return RetVal;
+}
diff --git a/source/packets/cPacket_PlayerListItem.h b/source/packets/cPacket_PlayerListItem.h
new file mode 100644
index 000000000..a4e10eb74
--- /dev/null
+++ b/source/packets/cPacket_PlayerListItem.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include "cPacket.h"
+#include "PacketID.h"
+
+class cPacket_PlayerListItem : public cPacket
+{
+public:
+ cPacket_PlayerListItem() { m_PacketID = E_PLAYER_LIST_ITEM; }
+
+ bool Parse(cSocket & a_Socket);
+ bool Send(cSocket & a_Socket);
+
+ virtual cPacket* Clone() const { return new cPacket_PlayerListItem(*this); }
+
+ std::string m_PlayerName; // Supports chat coloring, limited to 16 characters.
+ bool m_Online;
+ short m_Ping;
+
+ static const unsigned int c_Size = 6; // Minimal size ( 6 + string )
+}; \ No newline at end of file
diff --git a/source/packets/cPacket_WindowClose.h b/source/packets/cPacket_WindowClose.h
index 1940eec0a..4784586a2 100644
--- a/source/packets/cPacket_WindowClose.h
+++ b/source/packets/cPacket_WindowClose.h
@@ -14,7 +14,7 @@ public:
bool Parse(cSocket & a_Socket);
bool Send(cSocket & a_Socket);
- char m_Close; // 1 = close
+ char m_Close; // m_Close == cWindow WindowType number
static const unsigned int c_Size = 1 + 1;
}; \ No newline at end of file