Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
improve handling of teams
Browse files Browse the repository at this point in the history
  • Loading branch information
icewind1991 committed Dec 16, 2017
1 parent 3759f60 commit 9d4da5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 7 additions & 4 deletions src/Data/PacketEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,17 @@ export class PacketEntity {
}

public getProperty(originTable: string, name: string) {
for (const prop of this.props) {
if (prop.definition.ownerTableName === originTable && prop.definition.name === name) {
return prop;
}
const prop = PacketEntity.getPropByFullName(this.props, `${originTable}.${name}`);
if (prop) {
return prop;
}
throw new Error(`Property not found in entity (${originTable}.${name})`);
}

public hasProperty(originTable: string, name: string) {
return PacketEntity.getPropByFullName(this.props, `${originTable}.${name}`) !== null;
}

public clone(): PacketEntity {
const result = new PacketEntity(this.serverClass, this.entityIndex, this.pvs);
for (const prop of this.props) {
Expand Down
5 changes: 2 additions & 3 deletions src/PacketHandler/PacketEntities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ function handleEntity(entity: PacketEntity, match: Match, message: PacketMessage
}
break;
case'CTFTeam':
try {
if (entity.hasProperty('DT_Team', 'm_iTeamNum')) {
const teamId = entity.getProperty('DT_Team', 'm_iTeamNum').value as TeamNumber;
if (!match.teams.has(teamId)) {
const team = {
Expand All @@ -185,7 +185,7 @@ function handleEntity(entity: PacketEntity, match: Match, message: PacketMessage
match.teams.set(teamId, team);
match.teamEntityMap.set(entity.entityIndex, team);
}
} catch (e) {
} else {
const team = match.teamEntityMap.get(entity.entityIndex);
if (!team) {
throw new Error(`No team with entity id: ${entity.entityIndex}`);
Expand All @@ -208,7 +208,6 @@ function handleEntity(entity: PacketEntity, match: Match, message: PacketMessage

}
}
// process.exit();
}
break;
case 'CObjectSentrygun':
Expand Down

0 comments on commit 9d4da5d

Please sign in to comment.