static void client_read_trooper(const remote_process_client *client, struct ct_trooper *trooper) {
    if (!READ_BOOL()) {
        exit(10006);
    }
    memset(trooper, 0xCC, sizeof(*trooper));

    trooper->id = READ_INT64();
    trooper->position.x = READ_INT32();
    trooper->position.y = READ_INT32();
    trooper->player_id = READ_INT64();
    trooper->teammate_index = READ_INT32();
    trooper->is_teammate = READ_BOOL();
    trooper->type = READ_ENUM(ct_trooper_type);
    trooper->stance = READ_ENUM(ct_trooper_stance);
    trooper->hitpoints = READ_INT32();
    trooper->max_hitpoints = READ_INT32();
    trooper->action_points = READ_INT32();
    trooper->initial_action_points = READ_INT32();
    trooper->vision_range = READ_DOUBLE();
    trooper->shooting_range = READ_DOUBLE();
    trooper->shoot_cost = READ_INT32();
    trooper->standing_damage = READ_INT32();
    trooper->kneeling_damage = READ_INT32();
    trooper->prone_damage = READ_INT32();
    trooper->damage = READ_INT32();
    trooper->is_holding_grenade = READ_BOOL();
    trooper->is_holding_medkit = READ_BOOL();
    trooper->is_holding_field_ration = READ_BOOL();
}
static void client_read_cells(remote_process_client *client, struct ct_mutable_world *world) {
    int width, height, x, y;

    if (!client->cells_read)
    {
        client->cells_read = 1;
        memset(client->cells, 0, sizeof(client->cells));
        width = world->width;
        height = world->height;
        /* I won't actually read sizes here, instead I'll just verify their correctness */
        if (READ_INT32() != width) {
            exit(10007);
        }

        for (x = 0; x < width; ++x) {
            if (READ_INT32() != height) {
                exit(10008);
            }
            for (y = 0; y < height; ++y) {
                client->cells[y][x] = READ_ENUM(ct_cell_type);
            }
        }
    }
    assert(sizeof(client->cells) == sizeof(world->cells));
    memcpy(world->cells, client->cells, sizeof(client->cells));
}
int client_read_player_context(remote_process_client *client, struct ct_player_context *context) {
    enum ct_message_type message_type = READ_ENUM(ct_message_type);
    if (MSG_GAME_OVER == message_type) {
        return -1;
    }
    VERIFY(message_type, MSG_PLAYER_CONTEXT);
    if (!READ_BOOL()) {
        return -1;
    }
    client_read_trooper(client, &context->trooper);
    client_read_world(client, &context->world);
    return 0;
}
void client_read_game_context(const remote_process_client *client, struct ct_game *game) {
    VERIFY(READ_ENUM(ct_message_type), MSG_GAME_CONTEXT);
    if (!READ_BOOL()) {
        exit(10017);
    }

    memset(game, 0xCC, sizeof(struct ct_game));
    game->move_count = READ_INT32();
    game->last_player_elimination_score = READ_INT32();
    game->player_elimination_score = READ_INT32();
    game->trooper_elimination_score = READ_INT32();
    game->trooper_damage_score_factor = READ_DOUBLE();
    game->stance_change_cost = READ_INT32();
    game->standing_move_cost = READ_INT32();
    game->kneeling_move_cost = READ_INT32();
    game->prone_move_cost = READ_INT32();
    game->commander_aura_bonus_action_points = READ_INT32();
    game->commander_aura_range = READ_DOUBLE();
    game->commander_request_enemy_disposition_cost = READ_INT32();
    game->commander_request_enemy_disposition_max_offset = READ_INT32();
    game->field_medic_heal_cost = READ_INT32();
    game->field_medic_heal_bonus_hitpoints = READ_INT32();
    game->field_medic_heal_self_bonus_hitpoints = READ_INT32();
    game->sniper_standing_stealth_bonus = READ_DOUBLE();
    game->sniper_kneeling_stealth_bonus = READ_DOUBLE();
    game->sniper_prone_stealth_bonus = READ_DOUBLE();
    game->sniper_standing_shooting_range_bonus = READ_DOUBLE();
    game->sniper_kneeling_shooting_range_bonus = READ_DOUBLE();
    game->sniper_prone_shooting_range_bonus = READ_DOUBLE();
    game->scout_stealth_bonus_negation = READ_DOUBLE();
    game->grenade_throw_cost = READ_INT32();
    game->grenade_throw_range = READ_DOUBLE();
    game->grenade_direct_damage = READ_INT32();
    game->grenade_collateral_damage = READ_INT32();
    game->medikit_use_cost = READ_INT32();
    game->medikit_bonus_hitpoints = READ_INT32();
    game->medikit_heal_self_bonus_hitpoints = READ_INT32();
    game->field_ration_eat_cost = READ_INT32();
    game->field_ration_bonus_action_points = READ_INT32();
}
static void client_read_bonuses(const remote_process_client *client, struct ct_mutable_world *world) {
    int i;
    int bonuses_count = READ_INT32();
    world->bonuses_count = bonuses_count;

    if (bonuses_count < 0) {
        exit(10009);
    }

    world->bonuses = (struct ct_bonus*)malloc(bonuses_count * sizeof(struct ct_bonus));
    memset(world->bonuses, 0xCC, bonuses_count * sizeof(struct ct_bonus));

    for (i = 0; i < bonuses_count; ++i) {
        struct ct_bonus *bonus = &world->bonuses[i];
        if (!READ_BOOL()) {
            exit(10010);
        }
        bonus->id = READ_INT64();
        bonus->position.x = READ_INT32();
        bonus->position.y = READ_INT32();
        bonus->type = READ_ENUM(ct_bonus_type);
    }
}
示例#6
0
    QString read_item( IDispatchPtr dispatch, const QByteArray &record )
    {
        TRACE(OutlookSyncPlugin) << "OutlookTodoSync::read_item";
        Q_ASSERT( dispatch );
        Outlook::_TaskItemPtr item( dispatch );
        Outlook::UserPropertiesPtr props = item->GetUserProperties();
        Q_ASSERT(props);

        enum State {
            Idle, Categories
        };
        State state = Idle;

        QXmlStreamReader reader(record);
        QString key;
        QXmlStreamAttributes attributes;
        QString value;
        QStringList categories;
        while (!reader.atEnd()) {
            switch(reader.readNext()) {
                case QXmlStreamReader::StartElement:
                    key = reader.qualifiedName().toString();
                    value = QString();
                    attributes = reader.attributes();
                    if ( key == "Categories" )
                        state = Categories;
                    break;
                case QXmlStreamReader::Characters:
                    value += reader.text().toString();
                    break;
                case QXmlStreamReader::EndElement:
                    key = reader.qualifiedName().toString();
                    //LOG() << "key" << key << "value" << value;
                    READ_STRING(Description,Subject);
                    READ_ENUM(Priority,Importance,Outlook::olImportanceHigh,VeryHigh);
                    READ_ENUM(Priority,Importance,Outlook::olImportanceHigh,High);
                    READ_ENUM(Priority,Importance,Outlook::olImportanceNormal,Normal);
                    READ_ENUM(Priority,Importance,Outlook::olImportanceLow,Low);
                    READ_ENUM(Priority,Importance,Outlook::olImportanceLow,VeryLow);
                    // store the Qtopia value in a custom key then
                    // return this to Qtopia instead of "changing"
                    // the value (obviously this only works if you
                    // don't change the Outlook value to something
                    // else.
                    // eg. Qtopia:HV -> Outlook:H -> Sync:VH
                    // eg. Qtopia:HV -> Outlook:H -> User:N -> Sync:N
                    READ_CUSTOM(Priority,Qtopia Priority);
                    READ_ENUM(Status,Status,Outlook::olTaskNotStarted,NotStarted);
                    READ_ENUM(Status,Status,Outlook::olTaskInProgress,InProgress);
                    READ_ENUM(Status,Status,Outlook::olTaskComplete,Completed);
                    READ_ENUM(Status,Status,Outlook::olTaskWaiting,Waiting);
                    READ_ENUM(Status,Status,Outlook::olTaskDeferred,Deferred);
                    READ_DATE(DueDate,DueDate);
                    READ_DATE(StartedDate,StartDate);
                    READ_DATE(CompletedDate,DateCompleted);
                    READ_INT(PercentCompleted,PercentComplete);
                    READ_STRING(Notes,Body);
                    if ( state == Categories ) {
                        if ( key == "Category" )
                            categories << value;
                        if ( key == "Categories" ) {
                            item->PutCategories( qstring_to_bstr(categories.join(", ")) );
                            state = Idle;
                        }
                    }
                    break;
                default:
                    break;
            }
        }

        item->Save();
        return bstr_to_qstring(item->GetEntryID());
    }
示例#7
0
    QString read_item( const Outlook::_AppointmentItemPtr &item, QXmlStreamReader &reader, bool dump_exception )
    {
        TRACE(OutlookSyncPlugin) << "OutlookDatebookSync::read_item";

        Outlook::UserPropertiesPtr props = item->GetUserProperties();
        Q_ASSERT(props);

        // We need to clear the recurrence pattern now or we will fail to update recurring events
        if ( !dump_exception )
            item->ClearRecurrencePattern();

        enum State {
            Idle, When, Alarm, Repeat, Exception, Categories
        };
        State state = Idle;
        Outlook::RecurrencePatternPtr recpat = 0;

        QString key;
        QXmlStreamAttributes attributes;
        QString value;
        QStringList categories;
        bool utc = false;
        bool allday = false;
        while (!reader.atEnd()) {
            bool loop = true;
            switch(reader.readNext()) {
                case QXmlStreamReader::StartElement:
                    key = reader.qualifiedName().toString();
                    value = QString();
                    attributes = reader.attributes();
                    if ( key == "When" )
                        state = When;
                    if ( state == When && key == "StartDate" ) {
                        allday = true;
                    }
                    if ( state == When && key == "Start" ) {
                        allday = false;
                    }
                    if ( key == "Alarm" ) {
                        state = Alarm;
                        LOG() << "item->PutReminderSet" << false;
                        item->PutReminderSet( false );
                    }
                    if ( state == Alarm && key == "Type" || key == "Delay" ) {
                        // Outlook only wants to see alarms set on events in the future
                        // If we sync an event in the past with an alarm it will go off
                        // immediately, something that can be annoying when you do an
                        // initial sync with lots of events with alarms.
                        if ( date_to_qdatetime(item->GetStart()) > QDateTime::currentDateTime() ) {
                            LOG() << "item->PutReminderSet" << true;
                            item->PutReminderSet( true );
                        }
                    }
                    if ( !dump_exception ) {
                        if ( key == "Repeat" ) {
                            state = Repeat;
                        }
                        if ( state == Repeat && key == "Type" ) {
                            recpat = item->GetRecurrencePattern();
                            recpat->PutPatternStartDate( item->GetStart() );
                        }
                        if ( state == Repeat && key == "Exception" ) {
                            state = Exception;
                        }
                    }
                    if ( key == "Categories" )
                        state = Categories;
                    break;
                case QXmlStreamReader::Characters:
                    value += reader.text().toString();
                    break;
                case QXmlStreamReader::EndElement:
                    key = reader.qualifiedName().toString();
                    //LOG() << "key" << key << "value" << value;
                    READ_STRING(Description,Subject);
                    READ_STRING(Location,Location);
                    if ( key == "TimeZone" ) {
                        utc = ( !value.isEmpty() );
                    }
                    if ( state == When ) {
                        if ( allday ) {
                            item->PutAllDayEvent( true );
                            READ_DATE(StartDate,Start);
                            // We can't just read the end date because Outlook does it differently to Qtopia.
                            // Qtopia gives us something like "starts 7/10/08, ends 7/10/08" but Outlook
                            // expects "starts 7/10/08 00:00:00, ends 8/10/08 00:00:00".
                            // Simply add one day to the end date to get something Outlook won't barf over.
                            if ( key == "EndDate" ) {
                                QDate dt = stringToDate(value);
                                QDateTime actual( dt.addDays(1), QTime(0,0,0) );
                                LOG() << "item->PutEnd" << actual;
                                item->PutEnd( qdatetime_to_date(actual) );
                            }
                        } else {
                            item->PutAllDayEvent( false );
                            if ( key == "Start" ) {
                                QDateTime dt = stringToDateTime(value, utc);
                                if ( utc ) {
                                    dt.setTimeSpec( Qt::UTC );
                                    dt = dt.toLocalTime();
                                }
                                LOG() << "item->PutStart" << dt;
                                item->PutStart( qdatetime_to_date(dt) );
                            }
                            if ( key == "End" ) {
                                QDateTime dt = stringToDateTime(value, utc);
                                if ( utc ) {
                                    dt.setTimeSpec( Qt::UTC );
                                    dt = dt.toLocalTime();
                                }
                                LOG() << "item->PutEnd" << dt;
                                item->PutEnd( qdatetime_to_date(dt) );
                            }
                        }
                        if ( key == "When" )
                            state = Idle;
                    }
                    if ( state == Alarm ) {
                        READ_ENUM(Type,ReminderPlaySound,true,Audible);
                        READ_ENUM(Type,ReminderPlaySound,false,Visible);
                        READ_INT(Delay,ReminderMinutesBeforeStart);
                        if ( key == "Alarm" )
                            state = Idle;
                    }
                    if ( dump_exception == false && state == Repeat ) {
                        READ_ENUM_ITEM(Type,RecurrenceType,Outlook::olRecursDaily,Daily,recpat);
                        READ_ENUM_ITEM(Type,RecurrenceType,Outlook::olRecursWeekly,Weekly,recpat);
                        READ_ENUM_ITEM(Type,RecurrenceType,Outlook::olRecursMonthly,MonthlyDate,recpat);
                        READ_ENUM_ITEM(Type,RecurrenceType,Outlook::olRecursMonthNth,MonthlyDay,recpat);
                        READ_ENUM_ITEM(Type,RecurrenceType,Outlook::olRecursMonthNth,MonthlyEndDay,recpat);
                        READ_ENUM_ITEM(Type,RecurrenceType,Outlook::olRecursYearly,Yearly,recpat);
                        if ( key == "Type" ) {
                            if ( value == "MonthlyEndDay" ) {
                                LOG() << "recpat->PutInstance" << 5;
                                recpat->PutInstance( 5 );
                            }
                        }

                        if ( key == "Frequency" ) {
                            int interval = QVariant(value).toInt();
                            if ( interval >= 12 && interval % 12 == 0 ) {
                                // since interval is bigger than 12 yet divisible by 12 this is more
                                // likely to be a YearNth which Qtopia Sync Agent sends down as a
                                // MonthNth with interval *= 12
                                recpat->PutRecurrenceType( Outlook::olRecursYearNth );
                            }
                            LOG() << "recpat->PutInterval" << interval;
                            recpat->PutInterval( interval );
                        }

                        if ( key == "Until" ) {
                            if ( value.isEmpty() ) {
                                LOG() << "recpat->PutNoEndDate" << true;
                                recpat->PutNoEndDate( true );
                            } else {
                                LOG() << "recpat->PutPatternEndDate" << QDateTime( stringToDate(value), QTime(0,0,0) );
                                recpat->PutPatternEndDate( qdatetime_to_date(QDateTime( stringToDate(value), QTime(0,0,0) )) );
                            }
                        }

                        // Outlook doesn't seem to support Nearest == false (so ignore it)

                        if ( key == "WeekMask" ) {
                            int mask = 0;
                            foreach( const QString &v, value.split(" ") ) {
                                if ( v == "Monday" ) mask |= Outlook::olMonday;
                                else if ( v == "Tuesday" ) mask |= Outlook::olTuesday;
                                else if ( v == "Wednesday" ) mask |= Outlook::olWednesday;
                                else if ( v == "Thursday" ) mask |= Outlook::olThursday;
                                else if ( v == "Friday" ) mask |= Outlook::olFriday;
                                else if ( v == "Saturday" ) mask |= Outlook::olSaturday;
                                else if ( v == "Sunday" ) mask |= Outlook::olSunday;
                            }
                            LOG() << "recpat->PutDayOfWeekMask" << mask;
                            recpat->PutDayOfWeekMask( (Outlook::OlDaysOfWeek)mask );
                        }

                        if ( key == "Repeat" )
                            state = Idle;
                    }

                    if ( dump_exception == false && state == Exception ) {
                        if ( key == "OriginalDate" ) {
                            QDate exceptionDate = stringToDate(value);
                            Outlook::_AppointmentItemPtr eitem = recpat->GetOccurrence( qdatetime_to_date(QDateTime( exceptionDate, QTime(0,0,0) )) );
                            QString entryid = read_item( eitem, reader, true );
                            if ( entryid.isEmpty() )
                                state = Repeat; // the delete case eats the closing Exception tag
                        }
                        if ( key == "Exception" ) {
                            state = Repeat;
                        }
                    }

                    READ_STRING(Notes,Body);
                    if ( state == Categories ) {
                        if ( key == "Category" )
                            categories << value;
                        if ( key == "Categories" ) {
                            LOG() << "item->PutCategories" << categories;
                            item->PutCategories( qstring_to_bstr(categories.join(", ")) );
                            state = Idle;
                        }
                    }
                    READ_CUSTOM(TimeZone,Qtopia Timezone);

                    if ( dump_exception && key == "Appointment" )
                        loop = false;
                    if ( dump_exception && key == "Exception" ) {
                        // Oops... no Appointment tag in an Exception tag
                        // That means we need to delete the existing exception
                        item->Delete();
                        return QString();
                    }
            }
int client_read_team_size(const remote_process_client *client) {
    VERIFY(READ_ENUM(ct_message_type), MSG_TEAM_SIZE);
    return READ_INT32();
}