int SocketAddress::getPort() const { switch (getAddressType()) { case ADDRESS_TYPE_INET: return (int)ntohs(reinterpret_cast<const sockaddr_in *>(_platform_data)->sin_port); case ADDRESS_TYPE_INET6: return (int)ntohs(reinterpret_cast<const sockaddr_in6 *>(_platform_data)->sin6_port); default: return 0; } }
u_result SocketAddress::setPort(int port) { switch (getAddressType()) { case ADDRESS_TYPE_INET: reinterpret_cast<sockaddr_in *>(_platform_data)->sin_port = htons((short)port); break; case ADDRESS_TYPE_INET6: reinterpret_cast<sockaddr_in6 *>(_platform_data)->sin6_port = htons((short)port); break; default: return RESULT_OPERATION_FAIL; } return RESULT_OK; }
void gsc_kick_slot() { int id; char* msg; char* reason; if ( ! stackGetParams("is", &id, &msg)) { printf("scriptengine> ERROR: gsc_kick_slot(): param \"id\"[1] has to be an int!\n"); printf("scriptengine> ERROR: gsc_kick_slot(): param \"msg\"[2] has to be an string!\n"); stackPushUndefined(); return; } if(getAddressType(id) == NA_LOOPBACK) { stackReturnInt(0); return; // host } #if COD_VERSION == COD2_1_0 int guid_offset = 0x765F4; #elif COD_VERSION == COD2_1_2 int guid_offset = 0x76704; #elif COD_VERSION == COD2_1_3 int guid_offset = 0xAE704; #else #warning gsc_kick_slot() got no working addresses for guid_offset int guid_offset = 0x0; #endif int entity = PLAYERBASE(id); char* name = Info_ValueForKey((char*)entity+12, "name"); // read before drop client resets the userinfo int guid = *(int*)(entity + guid_offset); SV_DropClient(entity, msg); int * lastPacketTime = (int*)getLastPacketTime(id); *lastPacketTime = getSVSTime(); // in case there is a funny zombie (copied from Q3) if(!stackGetParamString(2, &reason)) { Com_Printf("%s (guid %i) was kicked\n", name, guid); stackReturnInt(1); return; } Com_Printf("%s (guid %i) was kicked for %s\n", name, guid, reason); stackReturnInt(1); }
u_result SocketAddress::getRawAddress(_u8 * buffer, size_t bufferSize) const { switch (getAddressType()) { case ADDRESS_TYPE_INET: if (bufferSize < sizeof(reinterpret_cast<const sockaddr_in *>(_platform_data)->sin_addr.s_addr)) return RESULT_INSUFFICIENT_MEMORY; memcpy(buffer, &reinterpret_cast<const sockaddr_in *>(_platform_data)->sin_addr.s_addr, sizeof(reinterpret_cast<const sockaddr_in *>(_platform_data)->sin_addr.s_addr)); break; case ADDRESS_TYPE_INET6: if (bufferSize < sizeof(reinterpret_cast<const sockaddr_in6 *>(_platform_data)->sin6_addr.s6_addr)) return RESULT_INSUFFICIENT_MEMORY; memcpy(buffer, reinterpret_cast<const sockaddr_in6 *>(_platform_data)->sin6_addr.s6_addr, sizeof(reinterpret_cast<const sockaddr_in6 *>(_platform_data)->sin6_addr.s6_addr)); break; default: return RESULT_OPERATION_FAIL; } return RESULT_OK; }
void gsc_player_addresstype(int id) { stackPushInt(getAddressType(id)); }
void NetworkDiscovery::getIP (QString address) { getIP (address, getAddressType (address)); }