Esempio n. 1
0
ScripMasterDataRequest::ScripMasterDataRequest(const char * buf)
{
  int offset = 0;
  UNSIGNED_INTEGER tmpInt1 = 0, tmpInt2 = 0;
  UNSIGNED_CHARACTER tmpChar = 0;
  UNSIGNED_LONG tmpLong1 = 0, tmpLong2 = 0;
  UNSIGNED_SHORT tmpShort1 = 0, tmpShort2 = 0;
  
  DESERIALIZE_8(tmpChar, setScripMasterDataRequestType(tmpChar), buf, offset);
  DESERIALIZE_32(tmpInt1, tmpInt2, setClientId(tmpInt2), buf, offset);
  DESERIALIZE_64(tmpLong1, tmpLong2, setRecordNumber(tmpLong2), buf, offset);
  DESERIALIZE_64(tmpLong1, tmpLong2, setSecurityId(tmpLong2), buf, offset);
  DESERIALIZE_64(tmpLong1, tmpLong2, setSymbolId(tmpLong2), buf, offset);
  DESERIALIZE_16(tmpShort1, tmpShort2, setExchangeId(tmpShort2), buf, offset);

  setSymbol(strdup(buf + offset));
  offset += SYMBOL_SIZE;
  setSeries(strdup(buf + offset));
  offset += SERIES_SIZE;
  setMarketName(strdup(buf + offset));
  offset += MARKET_NAME_SIZE;
  DESERIALIZE_8(tmpChar, setOptionType(tmpChar), buf, offset);
  DESERIALIZE_8(tmpChar, setOptionMode(tmpChar), buf, offset);
  DESERIALIZE_8(tmpChar, setSecurityType(tmpChar), buf, offset);
  DESERIALIZE_64(tmpLong1, tmpLong2, setStrikePrice(tmpLong2), buf, offset);
  DESERIALIZE_32(tmpInt1, tmpInt2, setExpiryYearMon(tmpInt2), buf, offset);
  DESERIALIZE_32(tmpInt1, tmpInt2, setExpiryDate(tmpInt2), buf, offset);
  DESERIALIZE_32(tmpInt1, tmpInt2, setNumberOfRecords(tmpInt2), buf, offset);
  setSymbolAlias(strdup(buf + offset));
  offset += SYMBOL_ALIAS_SIZE;

}
Esempio n. 2
0
O1Beatport::O1Beatport(QObject *parent) :
    O1(parent),
    _dialogContent(new Ui::BeatportAuthentication),
    _dialog(new QDialog),
    _status(InitialState)
{
    if(QByteArray(BEATPORT_API_KEY).isEmpty() || QByteArray(BEATPORT_API_SECRET).isEmpty()) {
        _status = APIKeysMissing;
        return;
    } else {
        setClientId(BEATPORT_API_KEY);
        setClientSecret(BEATPORT_API_SECRET);
    }

    _dialogContent->setupUi(_dialog);
    connect(_dialogContent->webView, &QWebView::linkClicked,
            this, &O1Beatport::onLinkClickedInsideWebView);

    setAccessTokenUrl(QUrl("https://oauth-api.beatport.com/identity/1/oauth/access-token"));
    setAuthorizeUrl(QUrl("https://oauth-api.beatport.com/identity/1/oauth/authorize"));
    setRequestTokenUrl(QUrl("https://oauth-api.beatport.com/identity/1/oauth/request-token"));

    connect(this, &O1::openBrowser, this, &O1Beatport::onOpenBrowser);
    connect(this, &O1::closeBrowser, _dialog, &QDialog::hide);
    connect(this, &O1::linkedChanged, this, &O1Beatport::onLinkingChanged);
    connect(this, &O1::linkingSucceeded, this, &O1Beatport::onLinkingSucceeded);
}
Esempio n. 3
0
void O1Tomboy::setBaseURL(const QString &value)
{
    setRequestTokenUrl(QUrl(value + QStringLiteral("/oauth/request_token")));
    setAuthorizeUrl(QUrl(value + QStringLiteral("/oauth/authorize")));
    setAccessTokenUrl(QUrl(value + QStringLiteral("/oauth/access_token")));
    setClientId(QStringLiteral("anyone"));
    setClientSecret(QStringLiteral("anyone"));
}
Esempio n. 4
0
void ItemType::unserialize(const BinaryTreePtr& node)
{
    m_null = false;

    m_category = (ItemCategory)node->getU8();

    node->getU32(); // flags

    static uint16 lastId = 99;
    while(node->canRead()) {
        uint8 attr = node->getU8();
        if(attr == 0 || attr == 0xFF)
            break;

        uint16 len = node->getU16();
        switch(attr) {
            case ItemTypeAttrServerId: {
                uint16 serverId = node->getU16();
                if(g_game.getClientVersion() < 960) {
                    if(serverId > 20000 && serverId < 20100) {
                        serverId -= 20000;
                    } else if(lastId > 99 && lastId != serverId - 1) {
                        while(lastId != serverId - 1) {
                            ItemTypePtr tmp(new ItemType);
                            tmp->setServerId(lastId++);
                            g_things.addItemType(tmp);
                        }
                    }
                } else {
                    if(serverId > 30000 && serverId < 30100) {
                        serverId -= 30000;
                    } else if(lastId > 99 && lastId != serverId - 1) {
                        while(lastId != serverId - 1) {
                            ItemTypePtr tmp(new ItemType);
                            tmp->setServerId(lastId++);
                            g_things.addItemType(tmp);
                        }
                    }
                }
                setServerId(serverId);
                lastId = serverId;
                break;
            }
            case ItemTypeAttrClientId:
                setClientId(node->getU16());
                break;
            case ItemTypeAttrName:
                setName(node->getString(len));
                break;
            case ItemTypeAttrWritable:
                m_attribs.set(ItemTypeAttrWritable, true);
                break;
            default:
                node->skip(len); // skip attribute
                break;
        }
    }
}
Esempio n. 5
0
bool EClientSocket::eConnect( const char *host, UINT port, int clientId, bool extraAuth)
{
	// already connected?
	if( isConnected()) {
		getWrapper()->error( NO_VALID_ID, ALREADY_CONNECTED.code(), ALREADY_CONNECTED.msg());
		return false;
	}

	// init sockets
	AfxSocketInit();

	// close open connection if there was one
	eDisconnect();

	// create socket
	m_pSocket.reset(new MySocket(this));
	if( !m_pSocket->Create()) {
		eDisconnect();
		getWrapper()->winError( "Failed to create socket", GetLastError() );
		getWrapper()->error( NO_VALID_ID, FAIL_CREATE_SOCK.code(), FAIL_CREATE_SOCK.msg());
		return false;
	}

	// use local machine if no host passed in
	if( !(host && *host)) {
		host = "127.0.0.1";
	}

	// connect to server
	if( !m_pSocket->Connect(host, port)) {
		int lastError = GetLastError();
		if( lastError != WSAEWOULDBLOCK && !handleSocketError(GetLastError())) {
			return false;
		}
	}

	setClientId( clientId);
	setExtraAuth( extraAuth);

	{
		// Wait till we are fully connected (or for an error)
		CWinThread* pThread = AfxGetThread();
		while( m_pSocket.get() && !isConnected()) {
			if (!pThread->PumpMessage())
				return false;
		}
	}
	return true;
}
Esempio n. 6
0
GoogleService::GoogleService(const AuthService& baseAuth)
  : OidcService(baseAuth)
{
  setRedirectEndpoint(configurationProperty(RedirectEndpointProperty));
  setClientId(configurationProperty(ClientIdProperty));
  setClientSecret(configurationProperty(ClientSecretProperty));

  setAuthEndpoint("https://accounts.google.com/o/oauth2/v2/auth");
  setTokenEndpoint("https://www.googleapis.com/oauth2/v4/token");
  setUserInfoEndpoint("https://www.googleapis.com/oauth2/v3/userinfo");

  setAuthenticationScope("openid email profile");

  setName("google");
  setDescription("Google Account");
  setPopupWidth(550);
}
Esempio n. 7
0
void Player::fromPacket(sf::Packet* packet) {

	int clientID;
	float ping;
	std::string userName;

	*packet >> clientID;
	*packet >> userName;
	*packet >> ping;

	setClientId(clientID);
	setUserName(userName);
	setPing(ping);

	ship.fromPacket(packet);

}
Esempio n. 8
0
 virtual void process( Message& m , AbstractMessagingPort* p ){
     Request r( m , p );
     if ( logLevel > 5 ){
         log(5) << "client id: " << hex << r.getClientId() << "\t" << r.getns() << "\t" << dec << r.op() << endl;
     }
     try {
         setClientId( r.getClientId() );
         r.process();
     }
     catch ( DBException& e ){
         m.data->id = r.id();
         log() << "UserException: " << e.what() << endl;
         if ( r.expectResponse() ){
             BSONObj err = BSON( "$err" << e.what() );
             replyToQuery( QueryResult::ResultFlag_ErrSet, p , m , err );
         }
     }
 }
Esempio n. 9
0
void Client::reloadSettings(bool updateNick) {
    const FavoriteHubEntry* hub = FavoriteManager::getInstance()->getFavoriteHubEntry(getHubUrl());

    string ClientId;
    if (::strncmp(getHubUrl().c_str(),"adc://", 6) == 0 ||
        ::strncmp(getHubUrl().c_str(),"adcs://", 6) == 0)
        ClientId = fullADCVersionString;
    else
        ClientId = fullVersionString;

    if(hub) {
        if(updateNick) {
            setCurrentNick(checkNick(hub->getNick(true)));
        }

        if(!hub->getUserDescription().empty()) {
            setCurrentDescription(hub->getUserDescription());
        } else {
            setCurrentDescription(SETTING(DESCRIPTION));
        }

        if(!hub->getPassword().empty())
            setPassword(hub->getPassword());
        if (hub->getOverrideId() && strlen(hub->getClientId().c_str()) > 1)
            ClientId = hub->getClientId();
        if (!hub->getExternalIP().empty())
            externalIP = hub->getExternalIP();
        if (!hub->getEncoding().empty()){
            setEncoding(hub->getEncoding());
        }
        if (hub->getUseInternetIP() && !SETTING(INTERNETIP).empty()){
            externalIP = SETTING(INTERNETIP);
        }
    } else {
        if(updateNick) {
            setCurrentNick(checkNick(SETTING(NICK)));
        }
        setCurrentDescription(SETTING(DESCRIPTION));
    }
    setClientId(ClientId);
}
Esempio n. 10
0
        virtual void process( Message& m , AbstractMessagingPort* p ){
            assert( p );
            Request r( m , p );

            LastError * le = lastError.startRequest( m , r.getClientId() );
            assert( le );
            
            if ( logLevel > 5 ){
                log(5) << "client id: " << hex << r.getClientId() << "\t" << r.getns() << "\t" << dec << r.op() << endl;
            }
            try {
                r.init();
                setClientId( r.getClientId() );
                r.process();
            }
            catch ( AssertionException & e ){
                log( e.isUserAssertion() ? 1 : 0 ) << "AssertionException in process: " << e.what() << endl;

                le->raiseError( e.getCode() , e.what() );
                
                m.header()->id = r.id();
                
                if ( r.expectResponse() ){
                    BSONObj err = BSON( "$err" << e.what() << "code" << e.getCode() );
                    replyToQuery( ResultFlag_ErrSet, p , m , err );
                }
            }
            catch ( DBException& e ){
                log() << "DBException in process: " << e.what() << endl;
                
                le->raiseError( e.getCode() , e.what() );
                
                m.header()->id = r.id();
                
                if ( r.expectResponse() ){
                    BSONObj err = BSON( "$err" << e.what() << "code" << e.getCode() );
                    replyToQuery( ResultFlag_ErrSet, p , m , err );
                }
            }
        }
Esempio n. 11
0
/**
 * Same as eConnect() except you may the specify address family here (default is
 * AF_UNSPEC).
 * We couldn't just add the new family arg to eConnect because the original one
 * is pure virtual declared in EClientSocketBase. Thanks C++ design crap ...
 */
bool EPosixClientSocket::eConnect2( const char *host, unsigned int port,
	int clientId, int family )
{
	// already connected?
	if( m_fd >= 0) {
		assert(false); // for now we don't allow that
		return true;
	}

	// initialize Winsock DLL (only for Windows)
	if ( !SocketsInit())	{
		// Does this set errno?
		getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(),
			"Initializing Winsock DLL failed.");
		return false;
	}

	// use local machine if no host passed in
	if ( !( host && *host)) {
		host = "127.0.0.1";
	}

	// starting to connect to server
	struct addrinfo *aitop;

	int s = resolveHost( host, port, family, &aitop );
	if( s != 0 ) {
		SocketsDestroy();
		const char *err;
#ifdef HAVE_GETADDRINFO
		err = gai_strerror(s);
#else
		err = "Invalid address, hostname resolving not supported.";
#endif
		getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), err );
		return false;
	}

	int con_errno = 0;
	for( struct addrinfo *ai = aitop; ai != NULL; ai = ai->ai_next ) {

		// create socket
		m_fd = socket(ai->ai_family, ai->ai_socktype, 0);
		if( m_fd < 0) {
			con_errno = errno;
			continue;
		}

		/* Set socket O_NONBLOCK. If wanted we could handle errors
		   (portability!) We could even make O_NONBLOCK optional. */
		int sn = set_socket_nonblock( m_fd );
		assert( sn == 0 );

		// try to connect
		if( timeout_connect( m_fd, ai->ai_addr, ai->ai_addrlen ) < 0 ) {
			con_errno = errno;
			SocketClose(m_fd);
			m_fd = -1;
			continue;
		}
		/* successfully  connected */
		break;
	}

	freeaddrinfo(aitop);

	/* connection failed, tell the error which happened in our last try  */
	if( m_fd < 0 ) {
		const char *err = strerror(con_errno);
		SocketsDestroy();
		getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), err );
		return false;
	}

	// set client id
	setClientId( clientId);

	errno = 0;
	onConnectBase();
	if( !isOutBufferEmpty() ) {
		/* For now we consider it as error if it's not possible to send an
		   integer string within a single tcp packet. Here we don't know weather
		   ::send() really failed or not. If so then we hopefully still have
		   it's errno set.*/
		const char *err = (errno != 0) ? strerror(errno)
			: "Sending client id failed.";
		eDisconnect();
		getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), err );
		return false;
	}

	if( wait_socket( m_fd, WAIT_READ ) <= 0 ) {
		const char *err = (errno != 0) ? strerror(errno) : strerror(ENODATA);
		eDisconnect();
		getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), err );
		return false;
	}

	while( !isConnected() ) {
		assert( isSocketOK() ); // need to be handled if send() would destroy it
		if ( !checkMessagesConnect()) {
			const char *err = (errno != 0) ? strerror(errno)
				: "The remote host closed the connection.";
			eDisconnect();
			getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), err );
			return false;
		}
	}
	// successfully connected
	return true;
}
Esempio n. 12
0
Player::Player(int clientID, std::string userName) {
	setClientId(clientID);
	setUserName(userName);

}
Esempio n. 13
0
Player::Player() {
	setClientId(-1);
	setUserName("<invalid>");
}
Esempio n. 14
0
bool EClientSocket::eConnectImpl(int clientId, bool extraAuth, ConnState* stateOutPt)
{
	// resolve host
	struct hostent* hostEnt = gethostbyname( host().c_str());
	if ( !hostEnt) {
		getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg());
		return false;
	}

	// create socket
	m_fd = socket(AF_INET, SOCK_STREAM, 0);

	// cannot create socket
	if( m_fd < 0) {
		getWrapper()->error( NO_VALID_ID, FAIL_CREATE_SOCK.code(), FAIL_CREATE_SOCK.msg());
		return false;
	}

	// starting to connect to server
	struct sockaddr_in sa;
	memset( &sa, 0, sizeof(sa));
	sa.sin_family = AF_INET;
	sa.sin_port = htons( port());
	sa.sin_addr.s_addr = ((in_addr*)hostEnt->h_addr)->s_addr;

	// try to connect
	if( (connect( m_fd, (struct sockaddr *) &sa, sizeof( sa))) < 0) {
		// error connecting
		SocketClose( m_fd);
		m_fd = -1;
		getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg());
		return false;
	}

    getTransport()->fd(m_fd);

	// set client id
	setClientId( clientId);
	setExtraAuth( extraAuth);

    int res = sendConnectRequest();

    if (res < 0 && !handleSocketError())
        return false;

	if( !isConnected()) {
		if( connState() != CS_DISCONNECTED) {
			assert( connState() == CS_REDIRECT);
			if( stateOutPt) {
				*stateOutPt = connState();
			}
			eDisconnect();
		}
		return false;
	}

	// set socket to non-blocking state
	if ( !SetSocketNonBlocking(m_fd)) {
	// error setting socket to non-blocking
		eDisconnect();
		getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg());
		return false;
	}

	assert( connState() == CS_CONNECTED);
	if( stateOutPt) {
		*stateOutPt = connState();
	}
            
    if (!m_asyncEConnect) {
        EReader reader(this, m_pSignal);

        while (m_pSignal && !m_serverVersion && isSocketOK()) {
            reader.checkClient();
            m_pSignal->waitForSignal();
            reader.processMsgs();
        }
    }

	// successfully connected
	return isSocketOK();
}
Esempio n. 15
0
bool EPosixClientSocket::eConnect( const char *host, unsigned int port, int clientId)
{
	// reset errno
	errno = 0;

	// already connected?
	if( m_fd >= 0) {
		errno = EISCONN;
		getWrapper()->error( NO_VALID_ID, ALREADY_CONNECTED.code(), ALREADY_CONNECTED.msg());
		return false;
	}

	// initialize Winsock DLL (only for Windows)
	if ( !SocketsInit())	{
		return false;
	}

	// create socket
	m_fd = socket(AF_INET, SOCK_STREAM, 0);

	// cannot create socket
	if( m_fd < 0) {
		// uninitialize Winsock DLL (only for Windows)
		SocketsDestroy();
		getWrapper()->error( NO_VALID_ID, FAIL_CREATE_SOCK.code(), FAIL_CREATE_SOCK.msg());
		return false;
	}

	// use local machine if no host passed in
	if ( !( host && *host)) {
		host = "127.0.0.1";
	}

	// starting to connect to server
	struct sockaddr_in sa;
	memset( &sa, 0, sizeof(sa));
	sa.sin_family = AF_INET;
	sa.sin_port = htons( port);
	sa.sin_addr.s_addr = inet_addr( host);

	// try to connect
	if( (connect( m_fd, (struct sockaddr *) &sa, sizeof( sa))) < 0) {
		// error connecting
		// uninitialize Winsock DLL (only for Windows)
		SocketsDestroy();
		getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg());
		return false;
	}

	// set client id
	setClientId( clientId);

	onConnectBase();

	while( isSocketOK() && !isConnected()) {
		if ( !checkMessages()) {
			// uninitialize Winsock DLL (only for Windows)
			SocketsDestroy();
			getWrapper()->error( NO_VALID_ID, CONNECT_FAIL.code(), CONNECT_FAIL.msg());
			return false;
		}
	}

	// successfully connected
	return true;
}