1
0

- Make Color was using 2 extra characters which took 2 characters off the 16 max (including color codes) for scoreboard display

- Added xC9 PlayerListItem packet and added code for player names to be added and removed from the scoreboard (need a catch-all for client disconnects: crashes, timeouts, etc)
 - Changed wid wording to a_WindowType

git-svn-id: http://mc-server.googlecode.com/svn/trunk@113 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
mtilden@gmail.com 2011-12-26 01:07:35 +00:00
parent e8f230f24e
commit bf838238e4
10 changed files with 91 additions and 5 deletions

View File

@ -316,6 +316,7 @@
<ClCompile Include="..\source\packets\cPacket_Explosion.cpp" /> <ClCompile Include="..\source\packets\cPacket_Explosion.cpp" />
<ClCompile Include="..\source\packets\cPacket_ItemData.cpp" /> <ClCompile Include="..\source\packets\cPacket_ItemData.cpp" />
<ClCompile Include="..\source\packets\cPacket_NewInvalidState.cpp" /> <ClCompile Include="..\source\packets\cPacket_NewInvalidState.cpp" />
<ClCompile Include="..\source\packets\cPacket_PlayerListItem.cpp" />
<ClCompile Include="..\source\packets\cPacket_SoundEffect.cpp" /> <ClCompile Include="..\source\packets\cPacket_SoundEffect.cpp" />
<ClCompile Include="..\source\packets\cPacket_Thunderbolt.cpp" /> <ClCompile Include="..\source\packets\cPacket_Thunderbolt.cpp" />
<ClCompile Include="..\source\packets\cPacket_EntityLook.cpp" /> <ClCompile Include="..\source\packets\cPacket_EntityLook.cpp" />
@ -470,6 +471,7 @@
<ClInclude Include="..\source\packets\cPacket_Explosion.h" /> <ClInclude Include="..\source\packets\cPacket_Explosion.h" />
<ClInclude Include="..\source\packets\cPacket_ItemData.h" /> <ClInclude Include="..\source\packets\cPacket_ItemData.h" />
<ClInclude Include="..\source\packets\cPacket_NewInvalidState.h" /> <ClInclude Include="..\source\packets\cPacket_NewInvalidState.h" />
<ClInclude Include="..\source\packets\cPacket_PlayerListItem.h" />
<ClInclude Include="..\source\packets\cPacket_SoundEffect.h" /> <ClInclude Include="..\source\packets\cPacket_SoundEffect.h" />
<ClInclude Include="..\source\packets\cPacket_Thunderbolt.h" /> <ClInclude Include="..\source\packets\cPacket_Thunderbolt.h" />
<ClInclude Include="..\source\packets\cPacket_EntityLook.h" /> <ClInclude Include="..\source\packets\cPacket_EntityLook.h" />

View File

@ -418,6 +418,9 @@
<Filter Include="cEntity\cPawn\cMonster\Personalities\PassiveAggressive"> <Filter Include="cEntity\cPawn\cMonster\Personalities\PassiveAggressive">
<UniqueIdentifier>{71574b1c-a518-4a17-92c1-e3ea340f73bc}</UniqueIdentifier> <UniqueIdentifier>{71574b1c-a518-4a17-92c1-e3ea340f73bc}</UniqueIdentifier>
</Filter> </Filter>
<Filter Include="Packets\cPacket_PlayerListItem">
<UniqueIdentifier>{b690d7b6-3697-4d91-bab3-21fd652986be}</UniqueIdentifier>
</Filter>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClCompile Include="..\source\cServer.cpp"> <ClCompile Include="..\source\cServer.cpp">
@ -835,6 +838,9 @@
<ClCompile Include="..\source\cPassiveMonster.cpp"> <ClCompile Include="..\source\cPassiveMonster.cpp">
<Filter>cEntity\cPawn\cMonster\Personalities\Passive</Filter> <Filter>cEntity\cPawn\cMonster\Personalities\Passive</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="..\source\packets\cPacket_PlayerListItem.cpp">
<Filter>Packets\cPacket_PlayerListItem</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="..\source\cServer.h"> <ClInclude Include="..\source\cServer.h">
@ -1287,6 +1293,9 @@
<ClInclude Include="..\source\cPassiveMonster.h"> <ClInclude Include="..\source\cPassiveMonster.h">
<Filter>cEntity\cPawn\cMonster\Personalities\Passive</Filter> <Filter>cEntity\cPawn\cMonster\Personalities\Passive</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="..\source\packets\cPacket_PlayerListItem.h">
<Filter>Packets\cPacket_PlayerListItem</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<None Include="..\source\AllToLua.pkg"> <None Include="..\source\AllToLua.pkg">

View File

@ -52,6 +52,7 @@ enum ENUM_PACKET_ID
E_INVENTORY_PROGRESS= 0x69, E_INVENTORY_PROGRESS= 0x69,
E_CREATE_INVENTORY_ACTION = 0x6B, E_CREATE_INVENTORY_ACTION = 0x6B,
E_UPDATE_SIGN = 0x82, E_UPDATE_SIGN = 0x82,
E_PLAYER_LIST_ITEM = 0xC9,
E_PING = 0xfe, E_PING = 0xfe,
E_DISCONNECT = 0xff, E_DISCONNECT = 0xff,
}; };

View File

@ -21,5 +21,5 @@ const std::string cChatColor::White = cChatColor::Color + "f";
const std::string cChatColor::MakeColor( char a_Color ) const std::string cChatColor::MakeColor( char a_Color )
{ {
return cChatColor::Color + a_Color; return cChatColor::Delimiter + a_Color;
} }

View File

@ -65,6 +65,7 @@
#include "packets/cPacket_13.h" #include "packets/cPacket_13.h"
#include "packets/cPacket_UpdateSign.h" #include "packets/cPacket_UpdateSign.h"
#include "packets/cPacket_Ping.h" #include "packets/cPacket_Ping.h"
#include "packets/cPacket_PlayerListItem.h"
#ifndef _WIN32 #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_UPDATE_SIGN] = new cPacket_UpdateSign;
m_pState->PacketMap[E_RESPAWN] = new cPacket_Respawn; m_pState->PacketMap[E_RESPAWN] = new cPacket_Respawn;
m_pState->PacketMap[E_PING] = new cPacket_Ping; 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 ); 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 ); cPacket_Chat DisconnectMessage( m_pState->Username + " disconnected: " + PacketData->m_Reason );
cRoot::Get()->GetServer()->Broadcast( DisconnectMessage ); 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(); Destroy();
return; return;

View File

@ -29,6 +29,7 @@
#include "packets/cPacket_Metadata.h" #include "packets/cPacket_Metadata.h"
#include "packets/cPacket_Chat.h" #include "packets/cPacket_Chat.h"
#include "packets/cPacket_NewInvalidState.h" #include "packets/cPacket_NewInvalidState.h"
#include "packets/cPacket_PlayerListItem.h"
#include "Vector3d.h" #include "Vector3d.h"
#include "Vector3f.h" #include "Vector3f.h"
@ -232,6 +233,20 @@ void cPlayer::Tick(float a_Dt)
if(e_EPMetaState == BURNING){ if(e_EPMetaState == BURNING){
InStateBurning(a_Dt); 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) { void cPlayer::InStateBurning(float a_Dt) {
@ -406,10 +421,10 @@ void cPlayer::OpenWindow( cWindow* a_Window )
m_CurrentWindow = 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( m_CurrentWindow ) m_CurrentWindow->Close( *this );
if (wID == 0) { if (a_WindowType == 0) {
if(GetInventory().GetWindow()->GetDraggingItem() && GetInventory().GetWindow()->GetDraggingItem()->m_ItemCount > 0) if(GetInventory().GetWindow()->GetDraggingItem() && GetInventory().GetWindow()->GetDraggingItem()->m_ItemCount > 0)
{ {
LOG("Player holds item! Dropping it..."); LOG("Player holds item! Dropping it...");

View File

@ -46,7 +46,7 @@ public:
cWindow* GetWindow() { return m_CurrentWindow; } cWindow* GetWindow() { return m_CurrentWindow; }
void OpenWindow( cWindow* a_Window ); void OpenWindow( cWindow* a_Window );
void CloseWindow(char wID); void CloseWindow(char a_WindowType);
cClientHandle* GetClientHandle() { return m_ClientHandle; } //tolua_export cClientHandle* GetClientHandle() { return m_ClientHandle; } //tolua_export
void SetClientHandle( cClientHandle* a_Client ) { m_ClientHandle = a_Client; } void SetClientHandle( cClientHandle* a_Client ) { m_ClientHandle = a_Client; }

View File

@ -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;
}

View File

@ -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 )
};

View File

@ -14,7 +14,7 @@ public:
bool Parse(cSocket & a_Socket); bool Parse(cSocket & a_Socket);
bool Send(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; static const unsigned int c_Size = 1 + 1;
}; };