예제 #1
0
void ServerManager::DestroyServerByName(string l_name, string s_name, WorldServer *ignore)
{
	list<WorldServer*>::iterator iter = world_servers.begin();
	while(iter != world_servers.end())
	{
		if((*iter) == ignore)
		{
			iter++;
		}

		if((*iter)->GetLongName().compare(l_name) == 0 && (*iter)->GetShortName().compare(s_name) == 0)
		{
			EmuTCPConnection *c = (*iter)->GetConnection();
			if(c->Connected())
			{
				c->Disconnect();
			}
			c->Free();
			delete (*iter);
			iter = world_servers.erase(iter);
		}

		iter++;
	}
}
예제 #2
0
void EmuTCPConnection::ProcessNetworkLayerPacket(ServerPacket* pack) {
	uint8 opcode = pack->pBuffer[0];
	uint8* data = &pack->pBuffer[1];
	switch (opcode) {
		case 0: {
			break;
		}
		case 1: { // Switch to RelayServer mode
			if (pack->size != 1) {
				SendNetErrorPacket("New RelayClient: wrong size, expected 1");
				break;
			}
			if (RelayServer) {
				SendNetErrorPacket("Switch to RelayServer mode when already in RelayServer mode");
				break;
			}
			if (RemoteID) {
				SendNetErrorPacket("Switch to RelayServer mode by a Relay Client");
				break;
			}
			if (ConnectionType != Incomming) {
				SendNetErrorPacket("Switch to RelayServer mode on outgoing connection");
				break;
			}
			#if TCPC_DEBUG >= 3
				struct in_addr	in;
				in.s_addr = GetrIP();
				std::cout << "Switching to RelayServer mode: " << inet_ntoa(in) << ":" << GetPort() << std::endl;
			#endif
			RelayServer = true;
			break;
		}
		case 2: { // New Relay Client
			if (!RelayServer) {
				SendNetErrorPacket("New RelayClient when not in RelayServer mode");
				break;
			}
			if (pack->size != 11) {
				SendNetErrorPacket("New RelayClient: wrong size, expected 11");
				break;
			}
			if (ConnectionType != Incomming) {
				SendNetErrorPacket("New RelayClient: illegal on outgoing connection");
				break;
			}
			EmuTCPConnection* con = new EmuTCPConnection(Server->GetNextID(), Server, this, *((uint32*) data), *((uint32*) &data[4]), *((uint16*) &data[8]));
			Server->AddConnection(con);
			RelayCount++;
			break;
		}
		case 3: { // Delete Relay Client
			if (!RelayServer) {
				SendNetErrorPacket("Delete RelayClient when not in RelayServer mode");
				break;
			}
			if (pack->size != 5) {
				SendNetErrorPacket("Delete RelayClient: wrong size, expected 5");
				break;
			}
			EmuTCPConnection* con = Server->FindConnection(*((uint32*)data));
			if (con) {
				if (ConnectionType == Incomming) {
					if (con->GetRelayLink() != this) {
						SendNetErrorPacket("Delete RelayClient: RelayLink != this");
						break;
					}
				}
				con->Disconnect(false);
			}
			break;
		}
		case 255: {
			#if TCPC_DEBUG >= 1
				struct in_addr	in;
				in.s_addr = GetrIP();
				std::cout "Received NetError: '";
				if (pack->size > 1)
					std::cout << (char*) data;
				std::cout << "': " << inet_ntoa(in) << ":" << GetPort() << std::endl;
			#endif
			break;
		}
	}
}