mirror of
https://github.com/JulianGro/overte.git
synced 2025-06-02 11:20:21 +02:00
create missing agents sent from the avatar mixer
This commit is contained in:
parent
06b794563f
commit
d895665d5f
2 changed files with 41 additions and 15 deletions
|
@ -23,11 +23,19 @@
|
||||||
using shared_lib::printLog;
|
using shared_lib::printLog;
|
||||||
|
|
||||||
Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentId) {
|
Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agentType, uint16_t thisAgentId) {
|
||||||
|
if (agentPublicSocket != NULL) {
|
||||||
publicSocket = new sockaddr;
|
publicSocket = new sockaddr;
|
||||||
memcpy(publicSocket, agentPublicSocket, sizeof(sockaddr));
|
memcpy(publicSocket, agentPublicSocket, sizeof(sockaddr));
|
||||||
|
} else {
|
||||||
|
publicSocket = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (agentLocalSocket != NULL) {
|
||||||
localSocket = new sockaddr;
|
localSocket = new sockaddr;
|
||||||
memcpy(localSocket, agentLocalSocket, sizeof(sockaddr));
|
memcpy(localSocket, agentLocalSocket, sizeof(sockaddr));
|
||||||
|
} else {
|
||||||
|
localSocket = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
type = agentType;
|
type = agentType;
|
||||||
agentId = thisAgentId;
|
agentId = thisAgentId;
|
||||||
|
@ -44,11 +52,19 @@ Agent::Agent(sockaddr *agentPublicSocket, sockaddr *agentLocalSocket, char agent
|
||||||
}
|
}
|
||||||
|
|
||||||
Agent::Agent(const Agent &otherAgent) {
|
Agent::Agent(const Agent &otherAgent) {
|
||||||
|
if (otherAgent.publicSocket != NULL) {
|
||||||
publicSocket = new sockaddr;
|
publicSocket = new sockaddr;
|
||||||
memcpy(publicSocket, otherAgent.publicSocket, sizeof(sockaddr));
|
memcpy(publicSocket, otherAgent.publicSocket, sizeof(sockaddr));
|
||||||
|
} else {
|
||||||
|
publicSocket = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (otherAgent.localSocket != NULL) {
|
||||||
localSocket = new sockaddr;
|
localSocket = new sockaddr;
|
||||||
memcpy(localSocket, otherAgent.localSocket, sizeof(sockaddr));
|
memcpy(localSocket, otherAgent.localSocket, sizeof(sockaddr));
|
||||||
|
} else {
|
||||||
|
localSocket = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
agentId = otherAgent.agentId;
|
agentId = otherAgent.agentId;
|
||||||
|
|
||||||
|
|
|
@ -130,10 +130,15 @@ void AgentList::processBulkAgentData(sockaddr *senderAddress, unsigned char *pac
|
||||||
|
|
||||||
int matchingAgentIndex = indexOfMatchingAgent(agentID);
|
int matchingAgentIndex = indexOfMatchingAgent(agentID);
|
||||||
|
|
||||||
if (matchingAgentIndex >= 0) {
|
if (matchingAgentIndex < 0) {
|
||||||
|
// we're missing this agent, we need to add it to the list
|
||||||
|
addOrUpdateAgent(NULL, NULL, AGENT_TYPE_AVATAR, agentID);
|
||||||
|
|
||||||
|
// theoretically if we can lock the vector we could assume this is size - 1
|
||||||
|
matchingAgentIndex = indexOfMatchingAgent(agentID);
|
||||||
|
}
|
||||||
|
|
||||||
updateAgentWithData(&agents[matchingAgentIndex], packetHolder, numBytesPerAgent + 1);
|
updateAgentWithData(&agents[matchingAgentIndex], packetHolder, numBytesPerAgent + 1);
|
||||||
}
|
|
||||||
|
|
||||||
currentPosition += numBytesPerAgent;
|
currentPosition += numBytesPerAgent;
|
||||||
}
|
}
|
||||||
|
@ -219,12 +224,16 @@ int AgentList::updateList(unsigned char *packetData, size_t dataBytes) {
|
||||||
bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType, uint16_t agentId) {
|
bool AgentList::addOrUpdateAgent(sockaddr *publicSocket, sockaddr *localSocket, char agentType, uint16_t agentId) {
|
||||||
std::vector<Agent>::iterator agent;
|
std::vector<Agent>::iterator agent;
|
||||||
|
|
||||||
|
if (publicSocket != NULL) {
|
||||||
for (agent = agents.begin(); agent != agents.end(); agent++) {
|
for (agent = agents.begin(); agent != agents.end(); agent++) {
|
||||||
if (agent->matches(publicSocket, localSocket, agentType)) {
|
if (agent->matches(publicSocket, localSocket, agentType)) {
|
||||||
// we already have this agent, stop checking
|
// we already have this agent, stop checking
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
agent = agents.end();
|
||||||
|
}
|
||||||
|
|
||||||
if (agent == agents.end()) {
|
if (agent == agents.end()) {
|
||||||
// we didn't have this agent, so add them
|
// we didn't have this agent, so add them
|
||||||
|
@ -316,7 +325,8 @@ void *pingUnknownAgents(void *args) {
|
||||||
for(std::vector<Agent>::iterator agent = agentList->getAgents().begin();
|
for(std::vector<Agent>::iterator agent = agentList->getAgents().begin();
|
||||||
agent != agentList->getAgents().end();
|
agent != agentList->getAgents().end();
|
||||||
agent++) {
|
agent++) {
|
||||||
if (agent->getActiveSocket() == NULL) {
|
if (agent->getActiveSocket() == NULL
|
||||||
|
&& (agent->getPublicSocket() != NULL && agent->getLocalSocket() != NULL)) {
|
||||||
// ping both of the sockets for the agent so we can figure out
|
// ping both of the sockets for the agent so we can figure out
|
||||||
// which socket we can use
|
// which socket we can use
|
||||||
agentList->getAgentSocket().send(agent->getPublicSocket(), &PACKET_HEADER_PING, 1);
|
agentList->getAgentSocket().send(agent->getPublicSocket(), &PACKET_HEADER_PING, 1);
|
||||||
|
|
Loading…
Reference in a new issue