ICommandTargetProcessor
| 126 | |
| 127 | public: //ICommandTargetProcessor |
| 128 | bool ProcessCommandTarget(cmd_target_info_t *info) |
| 129 | { |
| 130 | List<SimpleMultiTargetFilter *>::iterator iter; |
| 131 | |
| 132 | for (iter = simpleMultis.begin(); iter != simpleMultis.end(); iter++) { |
| 133 | SimpleMultiTargetFilter *smtf = (*iter); |
| 134 | if (strcmp(smtf->pattern.c_str(), info->pattern) == 0) { |
| 135 | CellArray *array = new CellArray(1); |
| 136 | HandleSecurity sec(g_pCoreIdent, g_pCoreIdent); |
| 137 | Handle_t hndl = handlesys->CreateHandleEx(htCellArray, array, &sec, NULL, NULL); |
| 138 | AutoHandleCloner ahc(hndl, sec); |
| 139 | if (ahc.getClone() == BAD_HANDLE) { |
| 140 | logger->LogError("[SM] Could not allocate a handle (%s, %d)", __FILE__, __LINE__); |
| 141 | delete array; |
| 142 | return false; |
| 143 | } |
| 144 | |
| 145 | smtf->fun->PushString(info->pattern); |
| 146 | smtf->fun->PushCell(ahc.getClone()); |
| 147 | smtf->fun->PushCell(info->admin); |
| 148 | cell_t result = 0; |
| 149 | if (smtf->fun->Execute(&result) != SP_ERROR_NONE || !result) |
| 150 | return false; |
| 151 | |
| 152 | IGamePlayer *pAdmin = info->admin |
| 153 | ? playerhelpers->GetGamePlayer(info->admin) |
| 154 | : NULL; |
| 155 | |
| 156 | info->num_targets = 0; |
| 157 | for (size_t i = 0; i < array->size(); i++) { |
| 158 | cell_t client = *array->at(i); |
| 159 | IGamePlayer *pClient = playerhelpers->GetGamePlayer(client); |
| 160 | if (pClient == NULL || !pClient->IsConnected()) |
| 161 | continue; |
| 162 | if (playerhelpers->FilterCommandTarget(pAdmin, pClient, info->flags) == |
| 163 | COMMAND_TARGET_VALID) |
| 164 | { |
| 165 | info->targets[info->num_targets++] = client; |
| 166 | if (info->num_targets >= unsigned(info->max_targets)) |
| 167 | break; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | info->reason = info->num_targets > 0 |
| 172 | ? COMMAND_TARGET_VALID |
| 173 | : COMMAND_TARGET_EMPTY_FILTER; |
| 174 | if (info->num_targets) { |
| 175 | strncopy(info->target_name, smtf->phrase.c_str(), info->target_name_maxlength); |
| 176 | info->target_name_style = smtf->phraseIsML |
| 177 | ? COMMAND_TARGETNAME_ML |
| 178 | : COMMAND_TARGETNAME_RAW; |
| 179 | } |
| 180 | |
| 181 | return true; |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | return false; |
no test coverage detected