Fix tab list being stuffed on one server

This commit is contained in:
UnknownShadow200 2018-05-06 11:05:17 +10:00
parent 0f261a0d74
commit 0d5fb926aa
9 changed files with 20 additions and 52 deletions

View File

@ -183,7 +183,6 @@ namespace ClassicalSharp.Network {
UsingPlayerClick = false;
SupportsPartialMessages = false;
SupportsFullCP437 = false;
IProtocol.addEntityHack = true;
for (int i = 0; i < handlers.Length; i++) {
handlers[i] = null;

View File

@ -133,9 +133,9 @@ namespace ClassicalSharp.Network.Protocols {
string groupName = reader.ReadString();
byte groupRank = reader.ReadUInt8();
// Some server software will declare they support ExtPlayerList, but send AddEntity then AddPlayerName
// we need to workaround this case by removing all the tab names we added for the AddEntity packets
DisableAddEntityHack();
// Workaround for server software that declares support for ExtPlayerList, but sends AddEntity then AddPlayerName
int mask = id >> 3, bit = 1 << (id & 0x7);
classicTabList[mask] &= (byte)~bit;
AddTablistEntry((byte)id, playerName, listName, groupName, groupRank);
}
@ -143,6 +143,7 @@ namespace ClassicalSharp.Network.Protocols {
byte id = reader.ReadUInt8();
string displayName = reader.ReadString();
string skinName = reader.ReadString();
CheckName(id, ref displayName, ref skinName);
AddEntity(id, displayName, skinName, false);
}
@ -257,6 +258,7 @@ namespace ClassicalSharp.Network.Protocols {
byte id = reader.ReadUInt8();
string displayName = reader.ReadString();
string skinName = reader.ReadString();
CheckName(id, ref displayName, ref skinName);
AddEntity(id, displayName, skinName, true);
}

View File

@ -228,11 +228,10 @@ namespace ClassicalSharp.Network.Protocols {
CheckName(id, ref name, ref skin);
AddEntity(id, name, skin, true);
if (!addEntityHack) return;
// Workaround for some servers that declare they support ExtPlayerList,
// but doesn't send ExtAddPlayerName packets.
AddTablistEntry(id, name, name, "Players", 0);
needRemoveNames[id >> 3] |= (byte)(1 << (id & 0x7));
classicTabList[id >> 3] |= (byte)(1 << (id & 0x7));
}
void HandleEntityTeleport() {

View File

@ -20,8 +20,7 @@ namespace ClassicalSharp.Network.Protocols {
public abstract void Reset();
public abstract void Tick();
protected internal static bool addEntityHack = true;
protected static byte[] needRemoveNames = new byte[256 >> 3];
protected static byte[] classicTabList = new byte[256 >> 3];
protected void CheckName(byte id, ref string displayName, ref string skinName) {
displayName = Utils.RemoveEndPlus(displayName);
@ -72,10 +71,10 @@ namespace ClassicalSharp.Network.Protocols {
// See comment about some servers in HandleAddEntity
int mask = id >> 3, bit = 1 << (id & 0x7);
if (!addEntityHack || (needRemoveNames[mask] & bit) == 0) return;
if ((classicTabList[mask] & bit) == 0) return;
RemoveTablistEntry(id);
needRemoveNames[mask] &= (byte)~bit;
classicTabList[mask] &= (byte)~bit;
}
protected void UpdateLocation(byte playerId, LocationUpdate update, bool interpolate) {
@ -107,18 +106,5 @@ namespace ClassicalSharp.Network.Protocols {
game.EntityEvents.RaiseTabEntryRemoved(id);
TabList.Entries[id] = null;
}
protected void DisableAddEntityHack() {
if (!addEntityHack) return;
addEntityHack = false;
for (int id = 0; id < EntityList.MaxCount; id++) {
int mask = id >> 3, bit = 1 << (id & 0x7);
if ((needRemoveNames[mask] & bit) == 0) continue;
RemoveTablistEntry((byte)id);
needRemoveNames[mask] &= (byte)~bit;
}
}
}
}

View File

@ -47,8 +47,8 @@ void D3D9_FreeResource(GfxResourceID* resource) {
*resource = NULL;
if (refCount <= 0) return;
UInt64 addr = (UInt64)(*resource);
Platform_Log1("D3D9 resource has outstanding references! ID 0x%x", &addr);
UInt64 addr = (UInt64)(unk);
Platform_Log2("D3D9 resource has %i outstanding references! ID 0x%x", &refCount, &addr);
}
void D3D9_LoopUntilRetrieved(void) {

View File

@ -25,8 +25,7 @@
/*########################################################################################################################*
*-----------------------------------------------------Common handlers-----------------------------------------------------*
*#########################################################################################################################*/
bool addEntityHack = true;
UInt8 needRemoveNames[256 >> 3];
UInt8 classicTabList[256 >> 3];
#define Handlers_ReadBlock(stream) Stream_ReadU8(stream)
#define Handlers_WriteBlock(stream, value) Stream_WriteU8(stream, value)
@ -151,10 +150,10 @@ void Handlers_RemoveEntity(EntityID id) {
/* See comment about some servers in Classic_AddEntity */
Int32 mask = id >> 3, bit = 1 << (id & 0x7);
if (!addEntityHack || (needRemoveNames[mask] & bit) == 0) return;
if (!(classicTabList[mask] & bit)) return;
Handlers_RemoveTablistEntry(id);
needRemoveNames[mask] &= (UInt8)~bit;
classicTabList[mask] &= (UInt8)~bit;
}
void Handlers_UpdateLocation(EntityID playerId, LocationUpdate* update, bool interpolate) {
@ -164,20 +163,6 @@ void Handlers_UpdateLocation(EntityID playerId, LocationUpdate* update, bool int
}
}
void Handlers_DisableAddEntityHack(void) {
if (!addEntityHack) return;
addEntityHack = false;
Int32 id;
for (id = 0; id < ENTITIES_MAX_COUNT; id++) {
Int32 mask = id >> 3, bit = 1 << (id & 0x7);
if (!(needRemoveNames[mask] & bit)) continue;
Handlers_RemoveTablistEntry((EntityID)id);
needRemoveNames[mask] &= (UInt8)~bit;
}
}
/*########################################################################################################################*
*------------------------------------------------------WoM protocol-------------------------------------------------------*
@ -508,12 +493,11 @@ void Classic_AddEntity(Stream* stream) {
Handlers_CheckName(id, &name, &skin);
Handlers_AddEntity(id, &name, &skin, true);
if (!addEntityHack) return;
/* Workaround for some servers that declare support for ExtPlayerList but don't send ExtAddPlayerName */
String group = String_FromConst("Players");
Handlers_AddTablistEntry(id, &name, &name, &group, 0);
needRemoveNames[id >> 3] |= (UInt8)(1 << (id & 0x7));
classicTabList[id >> 3] |= (UInt8)(1 << (id & 0x7));
}
void Classic_EntityTeleport(Stream* stream) {
@ -872,9 +856,9 @@ void CPE_ExtAddPlayerName(Stream* stream) {
Handlers_RemoveEndPlus(&playerName);
Handlers_RemoveEndPlus(&listName);
/* Some server software will declare they support ExtPlayerList, but send AddEntity then AddPlayerName */
/* We need to workaround this case by removing all the tab names we added for the AddEntity packets */
Handlers_DisableAddEntityHack();
/* Workarond for server software that declares support for ExtPlayerList, but sends AddEntity then AddPlayerName */
Int32 mask = id >> 3, bit = 1 << (id & 0x7);
classicTabList[mask] &= (UInt8)~bit;
Handlers_AddTablistEntry((EntityID)id, &playerName, &listName, &groupName, groupRank);
}
@ -1366,7 +1350,6 @@ void BlockDefs_Reset(void) {
*-----------------------------------------------------Public handlers-----------------------------------------------------*
*#########################################################################################################################*/
void Handlers_Reset(void) {
addEntityHack = true;
Classic_Reset();
CPE_Reset();
BlockDefs_Reset();

View File

@ -12,7 +12,6 @@ typedef struct Stream_ Stream;
void Handlers_RemoveEntity(EntityID id);
void Handlers_Reset(void);
void Handlers_Tick(void);
void Handlers_RemoveEntity(EntityID id);
bool cpe_sendHeldBlock, cpe_useMessageTypes, cpe_needD3Fix, cpe_extEntityPos, cpe_blockPerms, cpe_fastMap;
void Classic_WriteChat(Stream* stream, STRING_PURE String* text, bool partial);

View File

@ -49,7 +49,7 @@ int main(void) {
String title = String_FromConst(PROGRAM_APP_NAME);
String rawArgs = Platform_GetCommandLineArgs();
rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25566");
// rawArgs = String_FromReadonly("UnknownShadow200 fff 127.0.0.1 25566");
//rawArgs = String_FromReadonly("UnknownShadow200");
String args[5]; UInt32 argsCount = Array_Elems(args);

View File

@ -58,7 +58,7 @@ typedef struct FontDesc_ { void* Handle; UInt16 Size, Style; } FontDesc;
#define Int32_MaxValue ((Int32)2147483647L)
#define UInt32_MaxValue ((UInt32)4294967295UL)
#define USE_DX true
#define USE_DX false
#if USE_DX
typedef void* GfxResourceID;