Exemple #1
0
//edited
void MainWindow::sendData(QString data) {
    AbstractSerial *tempDev = (AbstractSerial *) ioDev;
    tempDev->setDtr(true);
    tempDev->setRts(false);
    if(ioDev->write(data.toAscii()) == -1) {
         statusBar()->showMessage(tr("Can't send data!"));
         printChat(System, "Can't send data :o");
     } else {
         printChat(Send, data);
     }
    tempDev->setDtr(false);
    tempDev->setRts(true);
}
Exemple #2
0
void MainWindow::processData(QString data) {
    static QString buffer = "";
    buffer += data;
    if(data.isEmpty()) {
        printChat(Recieve, buffer);
        readWaitTimer->stop();
        buffer = "";
    } else {
        readWaitTimer->start(50);
    }
}
Exemple #3
0
AbstractCommand::PostAction
Time::doExecute( Context& txt )
{
    if (txt._args.size() > 1)
        return PA_USAGE;

    time_t now;
    if (!time( &now )) {
        txt._ebuf << "Unable to determine system time.";
        return PA_ERROR;
    }

    tm* lt = localtime( &now );
    char s[32];
    strftime( s, sizeof(s), "%I:%M%p %Z", lt );

    Buffer buf;
    buf << _name << ": " << xvalue( s );
    printChat( txt._client, buf );

    return PA_NONE;
}
Exemple #4
0
AbstractCommand::PostAction
ListPlayers::doExecute( Context& txt )
{
    if (txt._args.size() != 1)
        return PA_USAGE;

    if (level.numConnectedClients == 0) {
       Buffer buf;
       buf << _name << ": " << "No players connected.";
       printChat( txt._client, buf );
       return PA_NONE;
    }

    // initialize team data
    for (int i = 0; i < 4; i++) {
        Team& t = teams[i];

        t.colSlot  = xvalue;
        t.colLevel = xvalue;
        t.colName  = xvalue;

        t.colSlot.width = 1;
        t.colLevel.width = 1;

        t.colName.flags |= ios::left;
        t.colName.width = 15;
    }

    // convience refs
    Team& axis   = teams[0];
    Team& allies = teams[1];
    Team& specsL = teams[2];
    Team& specsR = teams[3];

    axis.colSlot.prefixOutside  = "| ";
    axis.colLevel.prefixOutside = " | ";
    axis.colName.prefixOutside  = " | ";

    allies.colSlot.prefixOutside  = " | ";
    allies.colLevel.prefixOutside = " | ";
    allies.colName.prefixOutside  = " | ";
    allies.colName.suffixOutside  = " |";

    specsL.colSlot = axis.colSlot;
    specsL.colLevel = axis.colLevel;
    specsL.colName = axis.colName;

    specsR.colSlot = allies.colSlot;
    specsR.colLevel = allies.colLevel;
    specsR.colName = allies.colName;

    // build data
    bool specLeft = true;
    for (int i = 0; i < level.numConnectedClients; i++ ) {
        const int slot = level.sortedClients[i];
        gentity_t& p = *(g_entities + slot);
        User& user = *connectedUsers[slot];

        Team* team;
        switch (p.client->sess.sessionTeam) {
            case TEAM_AXIS:
                team = &axis;
                break;

            case TEAM_ALLIES:
                team = &allies;
                break;

            default:
            case TEAM_SPECTATOR:
                team = specLeft ? &specsL : &specsR;
                specLeft = !specLeft;
                break;
        }

        team->members[slot] = connectedUsers[slot];

        static const float lf10 = logf(10);

        if (team->colSlot.width < ((logf(slot) / lf10) + 1))
            team->colSlot.width = int((logf(slot) / lf10) + 1);

        if (team->colLevel.width < ((logf(user.authLevel) / lf10) + 1))
            team->colLevel.width = int((logf(user.authLevel) / lf10) + 1);

        if (team->colName.width < int(str::etLength( user.namex )))
            team->colName.width = int(str::etLength( user.namex ));
    }

    if (axis.colSlot.width < specsL.colSlot.width)
        axis.colSlot.width = specsL.colSlot.width;
    else if (specsL.colSlot.width < axis.colSlot.width)
        specsL.colSlot.width = axis.colSlot.width;

    if (axis.colLevel.width < specsL.colLevel.width)
        axis.colLevel.width = specsL.colLevel.width;
    else if (specsL.colLevel.width < axis.colLevel.width)
        specsL.colLevel.width = axis.colLevel.width;

    if (axis.colName.width < specsL.colName.width)
        axis.colName.width = specsL.colName.width;
    else if (specsL.colName.width < axis.colName.width)
        specsL.colName.width = axis.colName.width;

    if (allies.colSlot.width < specsR.colSlot.width)
        allies.colSlot.width = specsR.colSlot.width;
    else if (specsR.colSlot.width < allies.colSlot.width)
        specsR.colSlot.width = allies.colSlot.width;

    if (allies.colLevel.width < specsR.colLevel.width)
        allies.colLevel.width = specsR.colLevel.width;
    else if (specsR.colLevel.width < allies.colLevel.width)
        specsR.colLevel.width = allies.colLevel.width;

    if (allies.colName.width < specsR.colName.width)
        allies.colName.width = specsR.colName.width;
    else if (specsR.colName.width < allies.colName.width)
        specsR.colName.width = allies.colName.width;

    string::size_type width =
          axis.colSlot.prefixOutside.length()  + axis.colSlot.width  + axis.colSlot.suffixOutside.length()
        + axis.colLevel.prefixOutside.length() + axis.colLevel.width + axis.colLevel.suffixOutside.length()
        + axis.colName.prefixOutside.length()  + axis.colName.width  + axis.colName.suffixOutside.length()

        + allies.colSlot.prefixOutside.length()  + allies.colSlot.width  + allies.colSlot.suffixOutside.length()
        + allies.colLevel.prefixOutside.length() + allies.colLevel.width + allies.colLevel.suffixOutside.length()
        + allies.colName.prefixOutside.length()  + allies.colName.width  + allies.colName.suffixOutside.length();

    string top;
    top += '/';
    top.append( width-2, '-' );
    top += '\\';

    string divider;
    divider += '|';
    divider.append( width-2, '-' );
    divider += '|';

    string bottom;
    bottom += '\\';
    bottom.append( width-2, '-' );
    bottom += '/';

    Buffer buf;
    buf << top;

    // output axis/allies
    bool needdiv = false;
    if (axis.members.size() || allies.members.size()) {
        needdiv = true;

        InlineText hlSlot  = axis.colSlot;
        InlineText hlLevel = axis.colLevel;
        InlineText hlName  = axis.colName;

        InlineText hrSlot  = allies.colSlot;
        InlineText hrLevel = allies.colLevel;
        InlineText hrName  = allies.colName;

        hlSlot.color  = xcheader;
        hlLevel.color = xcheader;
        hlName.color  = xcheader;

        hrSlot.color  = xcheader;
        hrLevel.color = xcheader;
        hrName.color  = xcheader;

        buf << '\n'
            << hlSlot( '#' )  << hlLevel( "L" ) << hlName( "AXIS" )
            << hrSlot( '#' )  << hrLevel( 'L' ) << hrName( "ALLLIES" )
            << '\n' << divider;
        outputRow( buf, axis, allies );
    }

    // output spectators left/right
    if (specsL.members.size() || specsR.members.size()) {
        const string title = "SPECTATORS";

        InlineText head = xheader;

        head.flags |= ios::left;
        head.prefixOutside = specsL.colSlot.prefixOutside;
        head.suffixOutside = specsR.colName.suffixOutside;
        head.width = width - specsL.colSlot.prefixOutside.length() - specsR.colName.suffixOutside.length();

        if (needdiv)
            buf << '\n' << divider;

        // center spec title
        string s;
        s.append( (head.width - title.length()) / 2, ' ' );
        s += title;

        buf << '\n' << head( s )
            << '\n' << divider;
        outputRow( buf, specsL, specsR );
    }

    buf << '\n' << bottom;
    print( txt._client, buf );

    return PA_NONE;
}
Exemple #5
0
AbstractCommand::PostAction
PanzerWar::doExecute( Context& txt )
{
    if (txt._args.size() > 2)
        return PA_USAGE;

    const bool enabled = cvars::bg_panzerWar.ivalue;
    Buffer buf;

    // If there are no arguments, just report status
    if (txt._args.size() == 1) {
        buf << _name << ": Panzer war is " << xvalue( enabled ? "enabled" : "disabled" ) << '.';
        printChat( txt._client, buf );
        return PA_NONE;
    }
        
    string action = txt._args[1];
    str::toLower(action);
    
    if (action == "on") {
        if (enabled) {
            txt._ebuf << "Panzer war is already " << xvalue( "enabled" ) << '.';
            return PA_ERROR;
        }

		for (int i = 0; i < level.numConnectedClients; i++) {
            gentity_t* ent = &g_entities[i];

            if (ent->client->sess.sessionTeam == TEAM_SPECTATOR)
                continue;

            G_Damage( ent, NULL, NULL, NULL, NULL, 10000, DAMAGE_JAY_NO_PROTECTION, MOD_UNKNOWN );
		}

        cvars::bg_panzerWar.set( "1" );
        buf << _name << ": Panzer war is now " << xvalue( "enabled" ) << '.';
        printCpm( txt._client, buf, true );
    }
    else if (action == "off") {
        if (!enabled) {
            txt._ebuf << "Panzer war is already " << xvalue( "disabled" ) << '.';
            return PA_ERROR;
        }

		for (int i = 0; i < level.numConnectedClients; i++) {
            gentity_t* ent = &g_entities[i];

            if (ent->client->sess.sessionTeam == TEAM_SPECTATOR)
                continue;

            G_Damage( ent, NULL, NULL, NULL, NULL, 10000, DAMAGE_JAY_NO_PROTECTION, MOD_UNKNOWN );
		}

        cvars::bg_panzerWar.set( "0" );
        buf << _name << ": Panzer war is now " << xvalue( "disabled" ) << '.';
        printCpm( txt._client, buf, true );
    }
    else {
        txt._ebuf << "Invalid argument: " << xvalue( txt._args[1] );
        return PA_ERROR;
    }

    return PA_NONE;
}