5 #define ARRAY_STRING_LENGTH 32
10 Handle:groupListCommand
13 new g_groupList[GroupCommands];
16 new Handle:g_configParser = INVALID_HANDLE;
25 new String:g_command[MAXPLAYERS+1][CMD_LENGTH];
26 new g_currentPlace[MAXPLAYERS+1][Places];
29 * What to put in the 'info' menu field (for PlayerList and Player_Team menus only)
33 ClientId, /** Client id number ( 1 - Maxplayers) */
34 UserId, /** Client userid */
35 Name, /** Client Name */
36 SteamId, /** Client Steamid */
37 IpAddress, /** Client's Ip Address */
38 UserId2 /** Userid (not prefixed with #) */
60 ExecuteType:Item_execute,
66 SubMenu_Type:Submenu_type,
67 String:Submenu_title[32],
68 PlayerMethod:Submenu_method,
70 Handle:Submenu_listdata
73 new Handle:g_DataArray;
78 g_DataArray = CreateArray(sizeof(itemInput));
80 new String:executeBuffer[32];
83 kvMenu = CreateKeyValues("Commands");
85 BuildPath(Path_SM, file, 255, "configs/dynamicmenu/menu.ini");
86 FileToKeyValues(kvMenu, file);
88 new String:name[NAME_LENGTH];
89 new String:buffer[NAME_LENGTH];
91 KvSetEscapeSequences(kvMenu, true);
93 if (!KvGotoFirstSubKey(kvMenu))
98 decl String:admin[30];
100 new TopMenuObject:categoryId;
104 KvGetSectionName(kvMenu, buffer, sizeof(buffer));
106 KvGetString(kvMenu, "admin", admin, sizeof(admin),"sm_admin");
108 if ((categoryId =FindTopMenuCategory(hAdminMenu, buffer)) == INVALID_TOPMENUOBJECT)
110 categoryId = AddToTopMenu(hAdminMenu,
112 TopMenuObject_Category,
113 DynamicMenuCategoryHandler,
114 INVALID_TOPMENUOBJECT,
121 if (!KvGotoFirstSubKey(kvMenu))
128 KvGetSectionName(kvMenu, buffer, sizeof(buffer));
130 KvGetString(kvMenu, "admin", admin, sizeof(admin),"");
132 if (admin[0] == '\0')
134 //No 'admin' keyvalue was found
135 //Use the first argument of the 'cmd' string instead
137 decl String:temp[64];
138 KvGetString(kvMenu, "cmd", temp, sizeof(temp),"");
140 BreakString(temp, admin, sizeof(admin));
144 KvGetString(kvMenu, "cmd", itemInput[Item_cmd], sizeof(itemInput[Item_cmd]));
145 KvGetString(kvMenu, "execute", executeBuffer, sizeof(executeBuffer));
147 if (StrEqual(executeBuffer, "server"))
149 itemInput[Item_execute] = Execute_Server;
151 else //assume player type execute
153 itemInput[Item_execute] = Execute_Player;
156 /* iterate all submenus and load data into itemInput[Item_submenus] (adt array handle) */
159 decl String:countBuffer[10] = "1";
161 decl String:inputBuffer[32];
163 while (KvJumpToKey(kvMenu, countBuffer))
165 new submenuInput[Submenu];
169 itemInput[Item_submenus] = CreateArray(sizeof(submenuInput));
172 KvGetString(kvMenu, "type", inputBuffer, sizeof(inputBuffer));
174 if (strncmp(inputBuffer,"group",5)==0)
176 if (StrContains(inputBuffer, "player") != -1)
178 submenuInput[Submenu_type] = SubMenu_GroupPlayer;
182 submenuInput[Submenu_type] = SubMenu_Group;
185 else if (StrEqual(inputBuffer,"mapcycle"))
187 submenuInput[Submenu_type] = SubMenu_MapCycle;
189 KvGetString(kvMenu, "path", inputBuffer, sizeof(inputBuffer),"mapcycle.txt");
191 submenuInput[Submenu_listdata] = CreateDataPack();
192 WritePackString(submenuInput[Submenu_listdata], inputBuffer);
193 ResetPack(submenuInput[Submenu_listdata]);
195 else if (StrContains(inputBuffer, "player") != -1)
197 submenuInput[Submenu_type] = SubMenu_Player;
199 else if (StrEqual(inputBuffer,"onoff"))
201 submenuInput[Submenu_type] = SubMenu_OnOff;
203 else //assume 'list' type
205 submenuInput[Submenu_type] = SubMenu_List;
207 submenuInput[Submenu_listdata] = CreateDataPack();
210 new String:value[64];
213 new bool:more = true;
219 Format(temp,3,"%i",i);
220 KvGetString(kvMenu, temp, value, sizeof(value), "");
222 Format(temp,5,"%i.",i);
223 KvGetString(kvMenu, temp, text, sizeof(text), value);
225 Format(temp,5,"%i*",i);
226 KvGetString(kvMenu, temp, admin, sizeof(admin),"");
235 WritePackString(submenuInput[Submenu_listdata], value);
236 WritePackString(submenuInput[Submenu_listdata], text);
237 WritePackString(submenuInput[Submenu_listdata], admin);
244 ResetPack(submenuInput[Submenu_listdata]);
245 submenuInput[Submenu_listcount] = listcount;
248 if ((submenuInput[Submenu_type] == SubMenu_Player) || (submenuInput[Submenu_type] == SubMenu_GroupPlayer))
250 KvGetString(kvMenu, "method", inputBuffer, sizeof(inputBuffer));
252 if (StrEqual(inputBuffer, "clientid"))
254 submenuInput[Submenu_method] = ClientId;
256 else if (StrEqual(inputBuffer, "steamid"))
258 submenuInput[Submenu_method] = SteamId;
260 else if (StrEqual(inputBuffer, "userid2"))
262 submenuInput[Submenu_method] = UserId2;
264 else if (StrEqual(inputBuffer, "userid"))
266 submenuInput[Submenu_method] = UserId;
268 else if (StrEqual(inputBuffer, "ip"))
270 submenuInput[Submenu_method] = IpAddress;
274 submenuInput[Submenu_method] = Name;
279 KvGetString(kvMenu, "title", inputBuffer, sizeof(inputBuffer));
280 strcopy(submenuInput[Submenu_title], sizeof(submenuInput[Submenu_title]), inputBuffer);
283 Format(countBuffer, sizeof(countBuffer), "%i", count);
285 PushArrayArray(itemInput[Item_submenus], submenuInput[0]);
290 /* Save this entire item into the global items array and add it to the menu */
292 new location = PushArrayArray(g_DataArray, itemInput[0]);
294 decl String:locString[10];
295 IntToString(location, locString, sizeof(locString));
297 AddToTopMenu(hAdminMenu,
300 DynamicMenuItemHandler,
306 } while (KvGotoNextKey(kvMenu));
310 } while (KvGotoNextKey(kvMenu));
317 if (g_configParser == INVALID_HANDLE)
319 g_configParser = SMC_CreateParser();
322 SMC_SetReaders(g_configParser, NewSection, KeyValue, EndSection);
324 if (g_groupList[groupListName] != INVALID_HANDLE)
326 CloseHandle(g_groupList[groupListName]);
329 if (g_groupList[groupListCommand] != INVALID_HANDLE)
331 CloseHandle(g_groupList[groupListCommand]);
334 g_groupList[groupListName] = CreateArray(ARRAY_STRING_LENGTH);
335 g_groupList[groupListCommand] = CreateArray(ARRAY_STRING_LENGTH);
337 decl String:configPath[256];
338 BuildPath(Path_SM, configPath, sizeof(configPath), "configs/dynamicmenu/adminmenu_grouping.txt");
340 if (!FileExists(configPath))
342 LogError("Unable to locate admin menu groups file: %s", configPath);
348 new SMCError:err = SMC_ParseFile(g_configParser, configPath, line);
349 if (err != SMCError_Okay)
351 decl String:error[256];
352 SMC_GetErrorString(err, error, sizeof(error));
353 LogError("Could not parse file (line %d, file \"%s\"):", line, configPath);
354 LogError("Parser encountered error: %s", error);
360 public SMCResult:NewSection(Handle:smc, const String:name[], bool:opt_quotes)
365 public SMCResult:KeyValue(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes)
367 PushArrayString(g_groupList[groupListName], key);
368 PushArrayString(g_groupList[groupListCommand], value);
371 public SMCResult:EndSection(Handle:smc)
373 g_groupCount = GetArraySize(g_groupList[groupListName]);
376 public DynamicMenuCategoryHandler(Handle:topmenu,
377 TopMenuAction:action,
378 TopMenuObject:object_id,
383 if ((action == TopMenuAction_DisplayTitle) || (action == TopMenuAction_DisplayOption))
385 GetTopMenuObjName(topmenu, object_id, buffer, maxlength);
389 public DynamicMenuItemHandler(Handle:topmenu,
390 TopMenuAction:action,
391 TopMenuObject:object_id,
396 if (action == TopMenuAction_DisplayOption)
398 GetTopMenuObjName(topmenu, object_id, buffer, maxlength);
400 else if (action == TopMenuAction_SelectOption)
402 new String:locString[10];
403 GetTopMenuInfoString(topmenu, object_id, locString, sizeof(locString));
405 new location = StringToInt(locString);
408 GetArrayArray(g_DataArray, location, output[0]);
410 strcopy(g_command[param], sizeof(g_command[]), output[Item_cmd]);
412 g_currentPlace[param][Place_Item] = location;
418 public ParamCheck(client)
420 new String:buffer[6];
421 new String:buffer2[6];
423 new outputItem[Item];
424 new outputSubmenu[Submenu];
426 GetArrayArray(g_DataArray, g_currentPlace[client][Place_Item], outputItem[0]);
428 if (g_currentPlace[client][Place_ReplaceNum] < 1)
430 g_currentPlace[client][Place_ReplaceNum] = 1;
433 Format(buffer, 5, "#%i", g_currentPlace[client][Place_ReplaceNum]);
434 Format(buffer2, 5, "@%i", g_currentPlace[client][Place_ReplaceNum]);
436 if (StrContains(g_command[client], buffer) != -1 || StrContains(g_command[client], buffer2) != -1)
438 GetArrayArray(outputItem[Item_submenus], g_currentPlace[client][Place_ReplaceNum] - 1, outputSubmenu[0]);
440 new Handle:itemMenu = CreateMenu(Menu_Selection);
442 if ((outputSubmenu[Submenu_type] == SubMenu_Group) || (outputSubmenu[Submenu_type] == SubMenu_GroupPlayer))
444 decl String:nameBuffer[ARRAY_STRING_LENGTH];
445 decl String:commandBuffer[ARRAY_STRING_LENGTH];
447 for (new i = 0; i<g_groupCount; i++)
449 GetArrayString(g_groupList[groupListName], i, nameBuffer, sizeof(nameBuffer));
450 GetArrayString(g_groupList[groupListCommand], i, commandBuffer, sizeof(commandBuffer));
451 AddMenuItem(itemMenu, commandBuffer, nameBuffer);
455 if (outputSubmenu[Submenu_type] == SubMenu_MapCycle)
457 decl String:path[200];
458 ReadPackString(outputSubmenu[Submenu_listdata], path, sizeof(path));
459 ResetPack(outputSubmenu[Submenu_listdata]);
461 new Handle:file = OpenFile(path, "rt");
462 new String:readData[128];
464 if(file != INVALID_HANDLE)
466 while(!IsEndOfFile(file) && ReadFileLine(file, readData, sizeof(readData)))
468 TrimString(readData);
470 if (IsMapValid(readData))
472 AddMenuItem(itemMenu, readData, readData);
477 else if ((outputSubmenu[Submenu_type] == SubMenu_Player) || (outputSubmenu[Submenu_type] == SubMenu_GroupPlayer))
479 new PlayerMethod:playermethod = outputSubmenu[Submenu_method];
481 new String:nameBuffer[32];
482 new String:infoBuffer[32];
485 //loop through players. Add name as text and name/userid/steamid as info
486 for (new i=1; i<=g_maxPlayers; i++)
488 if (IsClientInGame(i))
490 GetClientName(i, nameBuffer, 31);
492 switch (playermethod)
496 new userid = GetClientUserId(i);
497 Format(infoBuffer, sizeof(infoBuffer), "#%i", userid);
498 AddMenuItem(itemMenu, infoBuffer, nameBuffer);
502 new userid = GetClientUserId(i);
503 Format(infoBuffer, sizeof(infoBuffer), "%i", userid);
504 AddMenuItem(itemMenu, infoBuffer, nameBuffer);
508 GetClientAuthString(i, infoBuffer, sizeof(infoBuffer));
509 AddMenuItem(itemMenu, infoBuffer, nameBuffer);
513 GetClientIP(i, infoBuffer, sizeof(infoBuffer));
514 AddMenuItem(itemMenu, infoBuffer, nameBuffer);
518 AddMenuItem(itemMenu, nameBuffer, nameBuffer);
520 default: //assume client id
522 Format(temp,3,"%i",i);
523 AddMenuItem(itemMenu, temp, nameBuffer);
529 else if (outputSubmenu[Submenu_type] == SubMenu_OnOff)
531 AddMenuItem(itemMenu, "1", "On");
532 AddMenuItem(itemMenu, "0", "Off");
536 new String:value[64];
539 new String:admin[NAME_LENGTH];
541 for (new i=0; i<outputSubmenu[Submenu_listcount]; i++)
543 ReadPackString(outputSubmenu[Submenu_listdata], value, sizeof(value));
544 ReadPackString(outputSubmenu[Submenu_listdata], text, sizeof(text));
545 ReadPackString(outputSubmenu[Submenu_listdata], admin, sizeof(admin));
547 if (CheckCommandAccess(client, admin, 0))
549 AddMenuItem(itemMenu, value, text);
553 ResetPack(outputSubmenu[Submenu_listdata]);
556 SetMenuTitle(itemMenu, outputSubmenu[Submenu_title]);
558 DisplayMenu(itemMenu, client, MENU_TIME_FOREVER);
562 //nothing else need to be done. Run teh command.
564 DisplayTopMenu(hAdminMenu, client, TopMenuPosition_LastCategory);
566 if (outputItem[Item_execute] == Execute_Player) // assume 'player' type execute option
568 FakeClientCommand(client, g_command[client]);
570 else // assume 'server' type execute option
572 InsertServerCommand(g_command[client]);
576 g_command[client][0] = '\0';
577 g_currentPlace[client][Place_ReplaceNum] = 1;
581 public Menu_Selection(Handle:menu, MenuAction:action, param1, param2)
583 if (action == MenuAction_End)
588 if (action == MenuAction_Select)
590 new String:info[NAME_LENGTH];
593 new bool:found = GetMenuItem(menu, param2, info, sizeof(info));
600 new String:buffer[6];
601 new String:infobuffer[NAME_LENGTH+2];
602 Format(infobuffer, sizeof(infobuffer), "\"%s\"", info);
604 Format(buffer, 5, "#%i", g_currentPlace[param1][Place_ReplaceNum]);
605 ReplaceString(g_command[param1], sizeof(g_command[]), buffer, infobuffer);
606 //replace #num with the selected option (quoted)
608 Format(buffer, 5, "@%i", g_currentPlace[param1][Place_ReplaceNum]);
609 ReplaceString(g_command[param1], sizeof(g_command[]), buffer, info);
610 //replace @num with the selected option (unquoted)
612 // Increment the parameter counter.
613 g_currentPlace[param1][Place_ReplaceNum]++;
618 if (action == MenuAction_Cancel && param2 == MenuCancel_Exit)
620 //client exited we should go back to submenu i think
621 DisplayTopMenu(hAdminMenu, param1, TopMenuPosition_LastCategory);