Пример #1
0
void ClientInfo::selectItem( const QString& item )
{
    // item in listBox selected, use LIST or GET depending of the node type.
    if ( item.endsWith( "/" ) ) {
	sendToServer( List, infoPath->text() + item );
	infoPath->setText( infoPath->text() + item );
    } else 
	sendToServer( Get, infoPath->text() + item );
}
Пример #2
0
void LCD::setMusicRepeat(int repeat)
{
    if (!m_lcdReady || !m_lcdShowMusic)
        return;

    sendToServer(QString("SET_MUSIC_PLAYER_PROP REPEAT %1").arg(repeat));
}
Пример #3
0
bool registration(string name, string password){
    char wiad[49]="";

    if(name.length()>20){ cout << "Nazwa za dluga!\n"; return false; }
    if(password.length()>20){ cout << "Haslo za dlugie!\n"; return false; }

    string whole="register"+name+":"+password;
    strcat(wiad, whole.c_str());
    sendToServer(wiad);
    cout << "Wyslano\n";

    //while(1) {
        cout << "Oczekiwanie na info od serwera!\n";
        if(event.type == ENET_EVENT_TYPE_RECEIVE) {
            if(receive(event.packet->data, "GOOD")) {
                cout << "REJESTRACJA ZAKONCZONA POMYSLNIE!" << endl;
                return true;
                //break;
            }
            else if(receive(event.packet->data, "FAIL")) {
                cout << "REJESTRACJA ZAKONCZONA NEGATYWNIE!" << endl;
                return false;
                //break;
            }
        }
    //}
}
void TcpClientSocket::dataReceived()
{
    qDebug()<<"缓冲区现有字节"<<(bytesAvailable());
    //按照Demo改
    QDataStream in(this);
    QString Message;
    in.setVersion(QDataStream::Qt_5_5);
    quint16 size = 0;
    if(size == 0)
    {
        if(this->bytesAvailable() < sizeof(quint16))
            return;
        in >> size;
    }
    if(size == 0xFFFF) return;
    if(this->bytesAvailable() < size)
    {
        qDebug() << size << endl;
        return;
    }
    in >> Message;
    QByteArray string1 = Message.toUtf8();
    QJsonDocument ParseDocument = QJsonDocument::fromJson(string1);
    QJsonObject obj = ParseDocument.object();

    qDebug() << obj << endl;
    emit sendToServer(this->no,obj);

}
Пример #5
0
void LCD::setGenericBusy()
{
    if (!m_lcdReady || !m_lcdShowGeneric)
        return;

    sendToServer("SET_GENERIC_PROGRESS 1 0.0");
}
Пример #6
0
void sendMessageHidden(string str,string message){
	vector<string> temp;
	string ret;
	//string message;
	//cout << "Please enter your message to " << str << " : ";
	//getline(cin >> ws,message);
	temp.push_back("MSG");
	temp.push_back(username);
	temp.push_back(str);
	temp.push_back(currentDateTime());
	temp.push_back(message);
	ret = protocolMaker(temp);	
	if (sendToServer(ret) == 0){
		string path = "bin/client/message_history/";
		path += username;
		path += "-";
		path += str;
		path += ".txt";
		vector<string> data = readExternalFileAutoCreate(path);
		data.push_back(ret);
		//moveToBottom(path);
		//writeExternalFile(path,data);
		writeExternalFile2(path,ret); //append data baru aja
	}
	else{
		cout << "Failed to send messages or the user does not exist!" << endl << endl;
	}	
}
/** Sends a vote for the number of tracks from a client to the server. Note
 *  that even this client will only store the vote when it is received back
 *  from the server.
 *  \param player_id The global player id of the voting player.
 *  \param count NUmber of tracks to play.
 */
void ClientLobbyRoomProtocol::voteRaceCount(uint8_t player_id, uint8_t count)
{
    NetworkString *request = getNetworkString(3);
    request->addUInt8(LE_VOTE_RACE_COUNT).addUInt8(player_id).addUInt8(count);
    sendToServer(request, true);
    delete request;
}   // voteRaceCount
/** Called from the gui when a client clicked on 'continue' on the race result
 *  screen. It notifies the server that this client has exited the screen and
 *  is back at the lobby.
 */
void ClientLobbyRoomProtocol::doneWithResults()
{
    NetworkString *done = getNetworkString(1);
    done->addUInt8(LE_RACE_FINISHED_ACK);
    sendToServer(done, /*reliable*/true);
    delete done;
}   // doneWithResults
/** Sends a vote for the minor game mode from a client to the server. Note that
 *  even this client will only store the vote when it is received back from the
 *  server.
 *  \param player_id The global player id of the voting player.
 *  \param minor Voted minor mode.
 */
void ClientLobbyRoomProtocol::voteMinor(uint8_t player_id, uint32_t minor)
{
    NetworkString *request = getNetworkString(6);
    request->addUInt8(LE_VOTE_MINOR).addUInt8(player_id).addUInt32(minor);
    sendToServer(request, true);
    delete request;
}   // voteMinor
Пример #10
0
int sqlite3_client_close(sqlite3 *pDb){
  SqlMessage msg;
  msg.op = MSG_Close;
  msg.pDb = pDb;
  sendToServer(&msg);
  return msg.errCode;
}
Пример #11
0
int sqlite3_client_finalize(sqlite3_stmt *pStmt){
  SqlMessage msg;
  msg.op = MSG_Finalize;
  msg.pStmt = pStmt;
  sendToServer(&msg);
  return msg.errCode;
}
Пример #12
0
void Terminal::_prepareHeader(const QString & string)
{
	DataHeader head;
	head.SetAction(DataHeader::TERMINAL_JOB);
	head.setActionSpecs(string);
	emit sendToServer(head);
}
Пример #13
0
void LCD::setMusicShuffle(int shuffle)
{
    if (!m_lcdReady || !m_lcdShowMusic)
        return;

    sendToServer(QString("SET_MUSIC_PLAYER_PROP SHUFFLE %1").arg(shuffle));
}
Пример #14
0
size_t requestFromServer(const char * request, const size_t requestLen, const size_t hintLength, char ** outputBuffer) {
    sendToServer(request, requestLen);
    ssize_t requestLength = hintLength > MIN_LENGTH ? hintLength : MIN_LENGTH;
    size_t outputLength = 0;
    char * output = calloc(sizeof(char), requestLength);
    char * readBuffer = calloc(sizeof(char), requestLength);
    int done = 0;
    while (!done) {
        memset(readBuffer, 0, requestLength);
        ssize_t charactersRead = read(serverFd, readBuffer, requestLength);
		if (charactersRead < 0)
			break;
        size_t oldOutputLength = outputLength;
        outputLength += charactersRead;
        if (charactersRead == requestLength) {
            requestLength *= 2;
            readBuffer = realloc(readBuffer, requestLength);
        } else {
            done = 1;
        }
        output = realloc(output, outputLength);
        memcpy(output+oldOutputLength, readBuffer, charactersRead);
    }
    *outputBuffer = output;
    free(readBuffer);
    return outputLength;
}
Пример #15
0
void LCD::init()
{
    // Stop the timer
    m_retryTimer->stop();

    // Get LCD settings
    m_lcdShowMusic = (GetMythDB()->GetSetting("LCDShowMusic", "1") == "1");
    m_lcdShowTime = (GetMythDB()->GetSetting("LCDShowTime", "1") == "1");
    m_lcdShowChannel = (GetMythDB()->GetSetting("LCDShowChannel", "1") == "1");
    m_lcdShowGeneric = (GetMythDB()->GetSetting("LCDShowGeneric", "1") == "1");
    m_lcdShowVolume = (GetMythDB()->GetSetting("LCDShowVolume", "1") == "1");
    m_lcdShowMenu = (GetMythDB()->GetSetting("LCDShowMenu", "1") == "1");
    m_lcdShowRecStatus = (GetMythDB()->GetSetting("LCDShowRecStatus", "1") == "1");
    m_lcdKeyString = GetMythDB()->GetSetting("LCDKeyString", "ABCDEF");

    m_connected = true;
    m_lcdReady = true;

    // send buffer if there's anything in there
    if (m_sendBuffer.length() > 0)
    {
        sendToServer(m_sendBuffer);
        m_sendBuffer = "";
    }
}
Пример #16
0
int sqlite3_client_reset(sqlite3_stmt *pStmt){
  SqlMessage msg;
  msg.op = MSG_Reset;
  msg.pStmt = pStmt;
  sendToServer(&msg);
  return msg.errCode;
}
Пример #17
0
// ----------------------------------------------------------------------------
void GameEventsProtocol::sendStartupBoost(uint8_t kart_id)
{
    NetworkString *ns = getNetworkString();
    ns->setSynchronous(true);
    ns->addUInt8(GE_STARTUP_BOOST).addUInt8(kart_id);
    sendToServer(ns, /*reliable*/true);
    delete ns;
}   // sendStartupBoost
Пример #18
0
/*
** The following 6 routines are client-side implementations of the
** core SQLite interfaces:
**
**        sqlite3_open
**        sqlite3_prepare
**        sqlite3_step
**        sqlite3_reset
**        sqlite3_finalize
**        sqlite3_close
**
** Clients should use the following client-side routines instead of 
** the core routines above.
**
**        sqlite3_client_open
**        sqlite3_client_prepare
**        sqlite3_client_step
**        sqlite3_client_reset
**        sqlite3_client_finalize
**        sqlite3_client_close
**
** Each of these routines creates a message for the desired operation,
** sends that message to the server, waits for the server to process
** then message and return a response.
*/
int sqlite3_client_open(const char *zDatabaseName, sqlite3 **ppDb){
  SqlMessage msg;
  msg.op = MSG_Open;
  msg.zIn = zDatabaseName;
  sendToServer(&msg);
  *ppDb = msg.pDb;
  return msg.errCode;
}
Пример #19
0
void LCD::setGenericProgress(float value)
{
    if (!m_lcdReady || !m_lcdShowGeneric)
        return;

    value = std::min(std::max(0.0f, value), 1.0f);
    sendToServer(QString("SET_GENERIC_PROGRESS 0 %1").arg(value));
}
Пример #20
0
bool login(string name, string password, CPlayer* player, CCamera* camera){
    char wiad[49]="";

    if(name.length()>20){ cout << "Name too long!\n"; return false; }
    if(password.length()>20){ cout << "Password too long!\n"; return false; }

    string whole="login"+name+":"+password;
    strcat(wiad, whole.c_str());
    player->nick = name;
    sendToServer(wiad);

    cout << "Sent!\n";

    while(1) {
        if(event.type == ENET_EVENT_TYPE_RECEIVE) {

            if(receive(event.packet->data, "GOOD")) {
                cout << "\nLogged!\n" << endl;

                string wiad = getPacket(event.packet->data);

                string var = "";
                int index = 0, what = 0;
                for(int i = 5; i < wiad.size()+2; ++i) {
                    if(wiad[i] != ' ') {
                        var.resize(var.size()+1);
                        var[index] = wiad[i];
                        ++index;
                    }
                    else {
                        index = 0;
                        ++what;
                        if(what == 1) player->hair = atoi(var.c_str());
                        if(what == 2) player->head = atoi(var.c_str());
                        if(what == 3) player->body = atoi(var.c_str());
                        if(what == 4) player->leg = atoi(var.c_str());
                        if(what == 5) player->boots = atoi(var.c_str());
                        if(what == 6) player->pos.x = atoi(var.c_str());
                        if(what == 7) player->pos.y = atoi(var.c_str());
                        var = "";
                    }
                }

                camera->setPos(player->pos.x, player->pos.y);

                return true;
            }
            else if(receive(event.packet->data, "FAIL")) {
                cout << "\nError when logging!\n" << endl;
                return false;
            }
            else {
                cout << "\nUuu smieci dostaje!\n" << endl;
                return false;
            }
        }
    }
}
Пример #21
0
void LCD::stopAll()
{
    if (!m_lcdReady)
        return;

    LOG(VB_GENERAL, LOG_DEBUG, LOC + "stopAll");

    sendToServer("STOP_ALL");
}
Пример #22
0
void LCD::switchToNothing()
{
    if (!m_lcdReady)
        return;

    LOG(VB_GENERAL, LOG_DEBUG, LOC + "switchToNothing");

    sendToServer("SWITCH_TO_NOTHING");
}
Пример #23
0
void LCD::switchToVolume(const QString &app_name)
{
    if (!m_lcdReady || !m_lcdShowVolume)
        return;

    LOG(VB_GENERAL, LOG_DEBUG, LOC + "switchToVolume");

    sendToServer("SWITCH_TO_VOLUME " + quotedString(app_name));
}
Пример #24
0
void LCD::switchToTime()
{
    if (!m_lcdReady)
        return;

    LOG(VB_GENERAL, LOG_DEBUG, LOC + "switchToTime");

    sendToServer("SWITCH_TO_TIME");
}
Пример #25
0
void LCD::setSpeakerLEDs(enum LCDSpeakerSet speaker, bool on)
{
    if (!m_lcdReady)
        return;
    m_lcdLedMask &= ~SPEAKER_MASK;
    if (on)
        m_lcdLedMask |= speaker;
    sendToServer(QString("UPDATE_LEDS %1").arg(m_lcdLedMask));
}
Пример #26
0
void LCD::setMusicProgress(const QString &time, float value)
{
    if (!m_lcdReady || !m_lcdShowMusic)
        return;

    value = std::min(std::max(0.0f, value), 1.0f);
    sendToServer("SET_MUSIC_PROGRESS " + quotedString(time) + ' ' + 
            QString().setNum(value));    
}
Пример #27
0
void LCD::setVideoSrcLEDs(enum LCDVideoSourceSet vsrc, bool on)
{
    if (!m_lcdReady)
        return;
    m_lcdLedMask &= ~VSRC_MASK;
    if (on)
        m_lcdLedMask |=  vsrc;
    sendToServer(QString("UPDATE_LEDS %1").arg(m_lcdLedMask));
}
Пример #28
0
void LCD::setChannelProgress(const QString &time, float value)
{
    if (!m_lcdReady || !m_lcdShowChannel)
        return;

    value = std::min(std::max(0.0f, value), 1.0f);
    sendToServer(QString("SET_CHANNEL_PROGRESS %1 %2").arg(quotedString(time))
        .arg(value));
}
Пример #29
0
void LCD::setTunerLEDs(enum LCDTunerSet tuner, bool on)
{
    if (!m_lcdReady)
        return;
    m_lcdLedMask &= ~TUNER_MASK;
    if (on)
        m_lcdLedMask |=  tuner;
    sendToServer(QString("UPDATE_LEDS %1").arg(m_lcdLedMask));
}
Пример #30
0
void LCD::setFunctionLEDs(enum LCDFunctionSet func, bool on)
{
    if (!m_lcdReady)
        return;
    m_lcdLedMask &= ~FUNC_MASK;
    if (on)
        m_lcdLedMask |=  func;
    sendToServer(QString("UPDATE_LEDS %1").arg(m_lcdLedMask));
}