plugins/adminmenu/dynamicmenu.sp
author David Anderson <dvander@alliedmods.net>
Sat May 31 07:57:33 2008 +0000 (2008-05-31)
changeset 2099 b284c729ec08
parent 2079 a93d09d68015
child 2103 963c3e205090
permissions -rw-r--r--
removed dynamicmenu folder -- everything is consistent now
ds@1952
     1
ds@1952
     2
#define NAME_LENGTH 32
ds@1952
     3
#define CMD_LENGTH 255
ds@1952
     4
ds@1952
     5
#define ARRAY_STRING_LENGTH 32
ds@1952
     6
ds@1952
     7
enum GroupCommands
ds@1952
     8
{
ds@1952
     9
	Handle:groupListName,
ds@1952
    10
	Handle:groupListCommand	
ds@1952
    11
};
ds@1952
    12
ds@1952
    13
new g_groupList[GroupCommands];
ds@1952
    14
new g_groupCount;
ds@1952
    15
ds@1952
    16
new Handle:g_configParser = INVALID_HANDLE;
ds@1952
    17
ds@1952
    18
enum Places
ds@1952
    19
{
ds@1952
    20
	Place_Category,
ds@1952
    21
	Place_Item,
ds@1952
    22
	Place_ReplaceNum	
ds@1952
    23
};
ds@1952
    24
ds@1952
    25
new String:g_command[MAXPLAYERS+1][CMD_LENGTH];
ds@1952
    26
new g_currentPlace[MAXPLAYERS+1][Places];
ds@1952
    27
ds@1952
    28
/**
ds@1952
    29
 * What to put in the 'info' menu field (for PlayerList and Player_Team menus only)
ds@1952
    30
 */
ds@1952
    31
enum PlayerMethod
ds@1952
    32
{		
ds@1952
    33
	ClientId,				/** Client id number ( 1 - Maxplayers) */
ds@1952
    34
	UserId,					/** Client userid */
ds@1952
    35
	Name,					/** Client Name */
ds@1952
    36
	SteamId,				/** Client Steamid */
ds@1952
    37
	IpAddress,				/** Client's Ip Address */
ds@1952
    38
	UserId2					/** Userid (not prefixed with #) */
ds@1952
    39
};
ds@1952
    40
pred@1953
    41
enum ExecuteType
pred@1953
    42
{
pred@1953
    43
	Execute_Player,
pred@1953
    44
	Execute_Server
pred@1953
    45
}
pred@1953
    46
pred@1953
    47
enum SubMenu_Type
pred@1953
    48
{
pred@1953
    49
	SubMenu_Group,
pred@1953
    50
	SubMenu_GroupPlayer,
pred@1953
    51
	SubMenu_Player,
pred@1953
    52
	SubMenu_MapCycle,
pred@1953
    53
	SubMenu_List,
pred@1953
    54
	SubMenu_OnOff	
pred@1953
    55
}
pred@1953
    56
pred@1953
    57
enum Item
pred@1953
    58
{
pred@1953
    59
	String:Item_cmd[256],
pred@1953
    60
	ExecuteType:Item_execute,
pred@1953
    61
	Handle:Item_submenus
pred@1953
    62
}
pred@1953
    63
pred@1953
    64
enum Submenu
pred@1953
    65
{
pred@1953
    66
	SubMenu_Type:Submenu_type,
pred@1953
    67
	String:Submenu_title[32],
pred@1953
    68
	PlayerMethod:Submenu_method,
pred@1953
    69
	Submenu_listcount,
pred@1953
    70
	Handle:Submenu_listdata
pred@1953
    71
}
pred@1953
    72
pred@1953
    73
new Handle:g_DataArray;
pred@1953
    74
ds@1952
    75
BuildDynamicMenu()
ds@1952
    76
{
pred@1953
    77
	new itemInput[Item];
pred@1953
    78
	g_DataArray = CreateArray(sizeof(itemInput));
ds@1952
    79
	
pred@1953
    80
	new String:executeBuffer[32];
pred@1953
    81
	
pred@1953
    82
	new Handle:kvMenu;
pred@1953
    83
	kvMenu = CreateKeyValues("Commands");
dvander@2099
    84
	
ds@1952
    85
	new String:file[256];
dvander@2099
    86
	
dvander@2099
    87
	/* As a compatibility shim, we use the old file if it exists. */
ds@1952
    88
	BuildPath(Path_SM, file, 255, "configs/dynamicmenu/menu.ini");
dvander@2099
    89
	if (FileExists(file))
dvander@2099
    90
	{
dvander@2099
    91
		LogError("Warning! configs/dynamicmenu/menu.ini is now configs/adminmenu_custom.txt.");
dvander@2099
    92
		LogError("Read the 1.0.2 release notes, as the dynamicmenu folder has been removed.");
dvander@2099
    93
	}
dvander@2099
    94
	else
dvander@2099
    95
	{
dvander@2099
    96
		BuildPath(Path_SM, file, 255, "configs/adminmenu_custom.txt");
dvander@2099
    97
	}
dvander@2099
    98
	
pred@1953
    99
	FileToKeyValues(kvMenu, file);
ds@1952
   100
	
ds@1952
   101
	new String:name[NAME_LENGTH];
ds@1952
   102
	new String:buffer[NAME_LENGTH];
ds@1952
   103
	
pred@1953
   104
	KvSetEscapeSequences(kvMenu, true);
pred@1953
   105
		
pred@1953
   106
	if (!KvGotoFirstSubKey(kvMenu))
ds@1952
   107
	{
ds@1952
   108
		return;
ds@1952
   109
	}
ds@1952
   110
	
ds@1952
   111
	decl String:admin[30];
ds@1952
   112
	
ds@1952
   113
	new TopMenuObject:categoryId;
ds@1952
   114
	
ds@1952
   115
	do
ds@1952
   116
	{		
pred@1953
   117
		KvGetSectionName(kvMenu, buffer, sizeof(buffer));
ds@1952
   118
pred@1953
   119
		KvGetString(kvMenu, "admin", admin, sizeof(admin),"sm_admin");
ds@1952
   120
				
ds@1952
   121
		if ((categoryId =FindTopMenuCategory(hAdminMenu, buffer)) == INVALID_TOPMENUOBJECT)
ds@1952
   122
		{
ds@1952
   123
			categoryId = AddToTopMenu(hAdminMenu,
ds@1952
   124
							buffer,
ds@1952
   125
							TopMenuObject_Category,
ds@1952
   126
							DynamicMenuCategoryHandler,
ds@1952
   127
							INVALID_TOPMENUOBJECT,
ds@1952
   128
							admin,
ds@1952
   129
							ADMFLAG_GENERIC,
ds@1952
   130
							name);
ds@1952
   131
ds@1952
   132
		}
ds@1952
   133
		
pred@1953
   134
		if (!KvGotoFirstSubKey(kvMenu))
ds@1952
   135
		{
ds@1952
   136
			return;
ds@1952
   137
		}
ds@1952
   138
		
ds@1952
   139
		do
ds@1952
   140
		{		
pred@1953
   141
			KvGetSectionName(kvMenu, buffer, sizeof(buffer));
pred@1953
   142
			
pred@1953
   143
			KvGetString(kvMenu, "admin", admin, sizeof(admin),"");
ds@1952
   144
			
ds@1952
   145
			if (admin[0] == '\0')
ds@1952
   146
			{
ds@1952
   147
				//No 'admin' keyvalue was found
ds@1952
   148
				//Use the first argument of the 'cmd' string instead
ds@1952
   149
				
ds@1952
   150
				decl String:temp[64];
pred@1953
   151
				KvGetString(kvMenu, "cmd", temp, sizeof(temp),"");
ds@1952
   152
				
ds@1952
   153
				BreakString(temp, admin, sizeof(admin));
ds@1952
   154
			}
pred@1953
   155
			
pred@1953
   156
			
pred@1953
   157
			KvGetString(kvMenu, "cmd", itemInput[Item_cmd], sizeof(itemInput[Item_cmd]));	
pred@1953
   158
			KvGetString(kvMenu, "execute", executeBuffer, sizeof(executeBuffer));
pred@1953
   159
			
pred@1953
   160
			if (StrEqual(executeBuffer, "server"))
ds@1952
   161
			{
pred@1953
   162
				itemInput[Item_execute] = Execute_Server;
pred@1953
   163
			}
pred@1953
   164
			else //assume player type execute
pred@1953
   165
			{
pred@1953
   166
				itemInput[Item_execute] = Execute_Player;
ds@1952
   167
			}
pred@1953
   168
  							
pred@1953
   169
  			/* iterate all submenus and load data into itemInput[Item_submenus] (adt array handle) */
pred@1953
   170
  			
pred@1953
   171
  			new count = 1;
pred@1953
   172
  			decl String:countBuffer[10] = "1";
pred@1953
   173
  			
pred@1953
   174
  			decl String:inputBuffer[32];
pred@1953
   175
  			
pred@1953
   176
  			while (KvJumpToKey(kvMenu, countBuffer))
pred@1953
   177
  			{
pred@1953
   178
	  			new submenuInput[Submenu];
pred@1953
   179
	  			
pred@1953
   180
	  			if (count == 1)
pred@1953
   181
	  			{
pred@1953
   182
		  			itemInput[Item_submenus] = CreateArray(sizeof(submenuInput));	
pred@1953
   183
	  			}
pred@1953
   184
	  			
pred@1953
   185
	  			KvGetString(kvMenu, "type", inputBuffer, sizeof(inputBuffer));
pred@1953
   186
	  			
pred@1953
   187
	  			if (strncmp(inputBuffer,"group",5)==0)
pred@1953
   188
				{	
pred@1953
   189
					if (StrContains(inputBuffer, "player") != -1)
pred@1953
   190
					{			
pred@1953
   191
						submenuInput[Submenu_type] = SubMenu_GroupPlayer;
pred@1953
   192
					}
pred@1953
   193
					else
pred@1953
   194
					{
pred@1953
   195
						submenuInput[Submenu_type] = SubMenu_Group;
pred@1953
   196
					}
pred@1953
   197
				}			
pred@1953
   198
				else if (StrEqual(inputBuffer,"mapcycle"))
pred@1953
   199
				{
pred@1953
   200
					submenuInput[Submenu_type] = SubMenu_MapCycle;
pred@1953
   201
					
pred@1953
   202
					KvGetString(kvMenu, "path", inputBuffer, sizeof(inputBuffer),"mapcycle.txt");
pred@1953
   203
					
pred@1953
   204
					submenuInput[Submenu_listdata] = CreateDataPack();
pred@1953
   205
					WritePackString(submenuInput[Submenu_listdata], inputBuffer);
pred@1953
   206
					ResetPack(submenuInput[Submenu_listdata]);
pred@1953
   207
				}
pred@1953
   208
				else if (StrContains(inputBuffer, "player") != -1)
pred@1953
   209
				{			
pred@1953
   210
					submenuInput[Submenu_type] = SubMenu_Player;
pred@1953
   211
				}
pred@1953
   212
				else if (StrEqual(inputBuffer,"onoff"))
pred@1953
   213
				{
pred@1953
   214
					submenuInput[Submenu_type] = SubMenu_OnOff;
pred@1953
   215
				}		
pred@1953
   216
				else //assume 'list' type
pred@1953
   217
				{
pred@1953
   218
					submenuInput[Submenu_type] = SubMenu_List;
pred@1953
   219
					
pred@1953
   220
					submenuInput[Submenu_listdata] = CreateDataPack();
pred@1953
   221
					
pred@1953
   222
					new String:temp[6];
pred@1953
   223
					new String:value[64];
pred@1953
   224
					new String:text[64];
pred@1953
   225
					new i=1;
pred@1953
   226
					new bool:more = true;
pred@1953
   227
					
pred@1953
   228
					new listcount = 0;
pred@1953
   229
								
pred@1953
   230
					do
pred@1953
   231
					{
pred@1953
   232
						Format(temp,3,"%i",i);
pred@1953
   233
						KvGetString(kvMenu, temp, value, sizeof(value), "");
pred@1953
   234
						
pred@1953
   235
						Format(temp,5,"%i.",i);
pred@1953
   236
						KvGetString(kvMenu, temp, text, sizeof(text), value);
pred@1953
   237
						
pred@1953
   238
						Format(temp,5,"%i*",i);
pred@1953
   239
						KvGetString(kvMenu, temp, admin, sizeof(admin),"");	
pred@1953
   240
						
pred@1953
   241
						if (value[0]=='\0')
pred@1953
   242
						{
pred@1953
   243
							more = false;
pred@1953
   244
						}
pred@1953
   245
						else
pred@1953
   246
						{
pred@1953
   247
							listcount++;
pred@1953
   248
							WritePackString(submenuInput[Submenu_listdata], value);
pred@1953
   249
							WritePackString(submenuInput[Submenu_listdata], text);
pred@1953
   250
							WritePackString(submenuInput[Submenu_listdata], admin);
pred@1953
   251
						}
pred@1953
   252
						
pred@1953
   253
						i++;
pred@1953
   254
										
pred@1953
   255
					} while (more);
pred@1953
   256
					
pred@1953
   257
					ResetPack(submenuInput[Submenu_listdata]);
pred@1953
   258
					submenuInput[Submenu_listcount] = listcount;
pred@1953
   259
				}
pred@1953
   260
				
pred@1953
   261
				if ((submenuInput[Submenu_type] == SubMenu_Player) || (submenuInput[Submenu_type] == SubMenu_GroupPlayer))
pred@1953
   262
				{
pred@1953
   263
					KvGetString(kvMenu, "method", inputBuffer, sizeof(inputBuffer));
pred@1953
   264
					
pred@1953
   265
					if (StrEqual(inputBuffer, "clientid"))
pred@1953
   266
					{
pred@1953
   267
						submenuInput[Submenu_method] = ClientId;
pred@1953
   268
					}
pred@1953
   269
					else if (StrEqual(inputBuffer, "steamid"))
pred@1953
   270
					{
pred@1953
   271
						submenuInput[Submenu_method] = SteamId;
pred@1953
   272
					}
pred@1953
   273
					else if (StrEqual(inputBuffer, "userid2"))
pred@1953
   274
					{
pred@1953
   275
						submenuInput[Submenu_method] = UserId2;
pred@1953
   276
					}
pred@1953
   277
					else if (StrEqual(inputBuffer, "userid"))
pred@1953
   278
					{
pred@1953
   279
						submenuInput[Submenu_method] = UserId;
pred@1953
   280
					}
pred@1953
   281
					else if (StrEqual(inputBuffer, "ip"))
pred@1953
   282
					{
pred@1953
   283
						submenuInput[Submenu_method] = IpAddress;
pred@1953
   284
					}
pred@1953
   285
					else
pred@1953
   286
					{
pred@1953
   287
						submenuInput[Submenu_method] = Name;
pred@1953
   288
					}					
pred@1953
   289
					
pred@1953
   290
				}
pred@1953
   291
				
pred@1953
   292
				KvGetString(kvMenu, "title", inputBuffer, sizeof(inputBuffer));
pred@1953
   293
				strcopy(submenuInput[Submenu_title], sizeof(submenuInput[Submenu_title]), inputBuffer);
pred@1953
   294
	  			
pred@1953
   295
	  			count++;
pred@1953
   296
	  			Format(countBuffer, sizeof(countBuffer), "%i", count);
pred@1953
   297
	  			
pred@1953
   298
	  			PushArrayArray(itemInput[Item_submenus], submenuInput[0]);
pred@1953
   299
	  		
pred@1953
   300
	  			KvGoBack(kvMenu);	
pred@1953
   301
  			}
pred@1953
   302
  			
pred@1953
   303
  			/* Save this entire item into the global items array and add it to the menu */
pred@1953
   304
  			
pred@1953
   305
  			new location = PushArrayArray(g_DataArray, itemInput[0]);
ds@1952
   306
			
pred@1953
   307
			decl String:locString[10];
pred@1953
   308
			IntToString(location, locString, sizeof(locString));
pred@1953
   309
ds@1952
   310
			AddToTopMenu(hAdminMenu,
ds@1952
   311
							buffer,
ds@1952
   312
							TopMenuObject_Item,
ds@1952
   313
							DynamicMenuItemHandler,
ds@1952
   314
  							categoryId,
ds@1952
   315
  							admin,
ds@1952
   316
  							ADMFLAG_GENERIC,
pred@1953
   317
  							locString);			
ds@1952
   318
		
pred@1953
   319
		} while (KvGotoNextKey(kvMenu));
ds@1952
   320
		
pred@1953
   321
		KvGoBack(kvMenu);
ds@1952
   322
		
pred@1953
   323
	} while (KvGotoNextKey(kvMenu));
ds@1952
   324
	
pred@1953
   325
	CloseHandle(kvMenu);
ds@1952
   326
}
ds@1952
   327
ds@1952
   328
ParseConfigs()
ds@1952
   329
{
ds@1952
   330
	if (g_configParser == INVALID_HANDLE)
ds@1952
   331
	{
ds@1952
   332
		g_configParser = SMC_CreateParser();
ds@1952
   333
	}
ds@1952
   334
	
ds@1952
   335
	SMC_SetReaders(g_configParser, NewSection, KeyValue, EndSection);
ds@1952
   336
	
ds@1952
   337
	if (g_groupList[groupListName] != INVALID_HANDLE)
ds@1952
   338
	{
ds@1952
   339
		CloseHandle(g_groupList[groupListName]);
ds@1952
   340
	}
ds@1952
   341
	
ds@1952
   342
	if (g_groupList[groupListCommand] != INVALID_HANDLE)
ds@1952
   343
	{
ds@1952
   344
		CloseHandle(g_groupList[groupListCommand]);
ds@1952
   345
	}
ds@1952
   346
	
ds@1952
   347
	g_groupList[groupListName] = CreateArray(ARRAY_STRING_LENGTH);
ds@1952
   348
	g_groupList[groupListCommand] = CreateArray(ARRAY_STRING_LENGTH);
ds@1952
   349
	
ds@1952
   350
	decl String:configPath[256];
ds@1952
   351
	BuildPath(Path_SM, configPath, sizeof(configPath), "configs/dynamicmenu/adminmenu_grouping.txt");
dvander@2099
   352
	if (FileExists(configPath))
dvander@2099
   353
	{
dvander@2099
   354
		LogError("Warning! configs/dynamicmenu/adminmenu_grouping.txt is now configs/adminmenu_grouping.txt.");
dvander@2099
   355
		LogError("Read the 1.0.2 release notes, as the dynamicmenu folder has been removed.");
dvander@2099
   356
	}
dvander@2099
   357
	else
dvander@2099
   358
	{
dvander@2099
   359
		BuildPath(Path_SM, configPath, sizeof(configPath), "configs/adminmenu_grouping.txt");
dvander@2099
   360
	}
ds@1952
   361
	
ds@1952
   362
	if (!FileExists(configPath))
ds@1952
   363
	{
ds@1984
   364
		LogError("Unable to locate admin menu groups file: %s", configPath);
ds@1952
   365
			
ds@1952
   366
		return;		
ds@1952
   367
	}
ds@1952
   368
	
ds@1952
   369
	new line;
ds@1952
   370
	new SMCError:err = SMC_ParseFile(g_configParser, configPath, line);
ds@1952
   371
	if (err != SMCError_Okay)
ds@1952
   372
	{
ds@1952
   373
		decl String:error[256];
ds@1952
   374
		SMC_GetErrorString(err, error, sizeof(error));
ds@1952
   375
		LogError("Could not parse file (line %d, file \"%s\"):", line, configPath);
ds@1952
   376
		LogError("Parser encountered error: %s", error);
ds@1952
   377
	}
ds@1952
   378
	
ds@1952
   379
	return;
ds@1952
   380
}
ds@1952
   381
ds@1952
   382
public SMCResult:NewSection(Handle:smc, const String:name[], bool:opt_quotes)
ds@1952
   383
{
ds@1952
   384
ds@1952
   385
}
ds@1952
   386
ds@1952
   387
public SMCResult:KeyValue(Handle:smc, const String:key[], const String:value[], bool:key_quotes, bool:value_quotes)
ds@1952
   388
{
ds@1952
   389
	PushArrayString(g_groupList[groupListName], key);
ds@1952
   390
	PushArrayString(g_groupList[groupListCommand], value);
ds@1952
   391
}
ds@1952
   392
ds@1952
   393
public SMCResult:EndSection(Handle:smc)
ds@1952
   394
{
ds@1952
   395
	g_groupCount = GetArraySize(g_groupList[groupListName]);
ds@1952
   396
}
ds@1952
   397
ds@1952
   398
public DynamicMenuCategoryHandler(Handle:topmenu, 
ds@1952
   399
						TopMenuAction:action,
ds@1952
   400
						TopMenuObject:object_id,
ds@1952
   401
						param,
ds@1952
   402
						String:buffer[],
ds@1952
   403
						maxlength)
ds@1952
   404
{
ds@1952
   405
	if ((action == TopMenuAction_DisplayTitle) || (action == TopMenuAction_DisplayOption))
ds@1952
   406
	{
ds@1952
   407
		GetTopMenuObjName(topmenu, object_id, buffer, maxlength);
ds@1952
   408
	}
ds@1952
   409
}
ds@1952
   410
ds@1952
   411
public DynamicMenuItemHandler(Handle:topmenu, 
ds@1952
   412
					  TopMenuAction:action,
ds@1952
   413
					  TopMenuObject:object_id,
ds@1952
   414
					  param,
ds@1952
   415
					  String:buffer[],
ds@1952
   416
					  maxlength)
ds@1952
   417
{
ds@1952
   418
	if (action == TopMenuAction_DisplayOption)
ds@1952
   419
	{
ds@1952
   420
		GetTopMenuObjName(topmenu, object_id, buffer, maxlength);
ds@1952
   421
	}
ds@1952
   422
	else if (action == TopMenuAction_SelectOption)
ds@1952
   423
	{	
pred@1953
   424
		new String:locString[10];
pred@1953
   425
		GetTopMenuInfoString(topmenu, object_id, locString, sizeof(locString));
ds@1952
   426
		
pred@1953
   427
		new location = StringToInt(locString);
ds@1952
   428
		
pred@1953
   429
		new output[Item];
pred@1953
   430
		GetArrayArray(g_DataArray, location, output[0]);
ds@1952
   431
		
pred@1953
   432
		strcopy(g_command[param], sizeof(g_command[]), output[Item_cmd]);
ds@1952
   433
					
pred@1953
   434
		g_currentPlace[param][Place_Item] = location;
pred@2078
   435
		g_currentPlace[param][Place_ReplaceNum] = 1;
ds@1952
   436
		
ds@1952
   437
		ParamCheck(param);
ds@1952
   438
	}
ds@1952
   439
}
ds@1952
   440
ds@1952
   441
public ParamCheck(client)
ds@1952
   442
{
ds@1952
   443
	new String:buffer[6];
ds@1952
   444
	new String:buffer2[6];
ds@1952
   445
	
pred@1953
   446
	new outputItem[Item];
pred@1953
   447
	new outputSubmenu[Submenu];
pred@1953
   448
	
pred@1953
   449
	GetArrayArray(g_DataArray, g_currentPlace[client][Place_Item], outputItem[0]);
ds@1952
   450
		
ds@1952
   451
	if (g_currentPlace[client][Place_ReplaceNum] < 1)
ds@1952
   452
	{
ds@1952
   453
		g_currentPlace[client][Place_ReplaceNum] = 1;
ds@1952
   454
	}
ds@1952
   455
	
ds@1952
   456
	Format(buffer, 5, "#%i", g_currentPlace[client][Place_ReplaceNum]);
ds@1952
   457
	Format(buffer2, 5, "@%i", g_currentPlace[client][Place_ReplaceNum]);
ds@1952
   458
	
ds@1952
   459
	if (StrContains(g_command[client], buffer) != -1 || StrContains(g_command[client], buffer2) != -1)
ds@1952
   460
	{
pred@1953
   461
		GetArrayArray(outputItem[Item_submenus], g_currentPlace[client][Place_ReplaceNum] - 1, outputSubmenu[0]);
ds@1952
   462
		
ds@1952
   463
		new Handle:itemMenu = CreateMenu(Menu_Selection);
pred@2079
   464
		SetMenuExitBackButton(itemMenu, true);
ds@1952
   465
			
pred@1953
   466
		if ((outputSubmenu[Submenu_type] == SubMenu_Group) || (outputSubmenu[Submenu_type] == SubMenu_GroupPlayer))
ds@1952
   467
		{	
ds@1952
   468
			decl String:nameBuffer[ARRAY_STRING_LENGTH];
ds@1952
   469
			decl String:commandBuffer[ARRAY_STRING_LENGTH];
ds@1952
   470
		
ds@1952
   471
			for (new i = 0; i<g_groupCount; i++)
ds@1952
   472
			{			
ds@1952
   473
				GetArrayString(g_groupList[groupListName], i, nameBuffer, sizeof(nameBuffer));
ds@1952
   474
				GetArrayString(g_groupList[groupListCommand], i, commandBuffer, sizeof(commandBuffer));
ds@1952
   475
				AddMenuItem(itemMenu, commandBuffer, nameBuffer);
ds@1952
   476
			}
ds@1952
   477
		}
ds@1952
   478
		
pred@1953
   479
		if (outputSubmenu[Submenu_type] == SubMenu_MapCycle)
pred@1953
   480
		{	
ds@1952
   481
			decl String:path[200];
pred@1953
   482
			ReadPackString(outputSubmenu[Submenu_listdata], path, sizeof(path));
pred@1953
   483
			ResetPack(outputSubmenu[Submenu_listdata]);
ds@1952
   484
		
ds@1952
   485
			new Handle:file = OpenFile(path, "rt");
ds@1952
   486
			new String:readData[128];
ds@1952
   487
			
ds@1952
   488
			if(file != INVALID_HANDLE)
ds@1952
   489
			{
ds@1952
   490
				while(!IsEndOfFile(file) && ReadFileLine(file, readData, sizeof(readData)))
ds@1952
   491
				{
ds@1952
   492
					TrimString(readData);
ds@1952
   493
					
ds@1952
   494
					if (IsMapValid(readData))
ds@1952
   495
					{
ds@1952
   496
						AddMenuItem(itemMenu, readData, readData);
ds@1952
   497
					}
ds@1952
   498
				}
ds@1952
   499
			}
ds@1952
   500
		}
pred@1953
   501
		else if ((outputSubmenu[Submenu_type] == SubMenu_Player) || (outputSubmenu[Submenu_type] == SubMenu_GroupPlayer))
ds@1952
   502
		{
pred@1953
   503
			new PlayerMethod:playermethod = outputSubmenu[Submenu_method];
pred@1953
   504
		
ds@1952
   505
			new String:nameBuffer[32];
ds@1952
   506
			new String:infoBuffer[32];
ds@1952
   507
			new String:temp[4];
ds@1952
   508
			
ds@1952
   509
			//loop through players. Add name as text and name/userid/steamid as info
ds@1952
   510
			for (new i=1; i<=g_maxPlayers; i++)
ds@1952
   511
			{
ds@1952
   512
				if (IsClientInGame(i))
ds@1952
   513
				{			
ds@1952
   514
					GetClientName(i, nameBuffer, 31);
ds@1952
   515
					
ds@1952
   516
					switch (playermethod)
ds@1952
   517
					{
ds@1952
   518
						case UserId:
ds@1952
   519
						{
ds@1952
   520
							new userid = GetClientUserId(i);
ds@1952
   521
							Format(infoBuffer, sizeof(infoBuffer), "#%i", userid);
ds@1952
   522
							AddMenuItem(itemMenu, infoBuffer, nameBuffer);	
ds@1952
   523
						}
ds@1952
   524
						case UserId2:
ds@1952
   525
						{
ds@1952
   526
							new userid = GetClientUserId(i);
ds@1952
   527
							Format(infoBuffer, sizeof(infoBuffer), "%i", userid);
ds@1952
   528
							AddMenuItem(itemMenu, infoBuffer, nameBuffer);							
ds@1952
   529
						}
ds@1952
   530
						case SteamId:
ds@1952
   531
						{
ds@1952
   532
							GetClientAuthString(i, infoBuffer, sizeof(infoBuffer));
ds@1952
   533
							AddMenuItem(itemMenu, infoBuffer, nameBuffer);							
ds@1952
   534
						}	
ds@1952
   535
						case IpAddress:
ds@1952
   536
						{
ds@1952
   537
							GetClientIP(i, infoBuffer, sizeof(infoBuffer));
ds@1952
   538
							AddMenuItem(itemMenu, infoBuffer, nameBuffer);							
ds@1952
   539
						}
ds@1952
   540
						case Name:
ds@1952
   541
						{
ds@1952
   542
							AddMenuItem(itemMenu, nameBuffer, nameBuffer);
ds@1952
   543
						}	
ds@1952
   544
						default: //assume client id
ds@1952
   545
						{
ds@1952
   546
							Format(temp,3,"%i",i);
ds@1952
   547
							AddMenuItem(itemMenu, temp, nameBuffer);						
ds@1952
   548
						}								
ds@1952
   549
					}
ds@1952
   550
				}
ds@1952
   551
			}
ds@1952
   552
		}
pred@1953
   553
		else if (outputSubmenu[Submenu_type] == SubMenu_OnOff)
ds@1952
   554
		{
ds@1952
   555
			AddMenuItem(itemMenu, "1", "On");
ds@1952
   556
			AddMenuItem(itemMenu, "0", "Off");
ds@1952
   557
		}		
ds@1952
   558
		else
ds@1952
   559
		{
ds@1952
   560
			new String:value[64];
ds@1952
   561
			new String:text[64];
ds@1952
   562
					
ds@1952
   563
			new String:admin[NAME_LENGTH];
pred@1953
   564
			
pred@1953
   565
			for (new i=0; i<outputSubmenu[Submenu_listcount]; i++)
ds@1952
   566
			{
pred@1953
   567
				ReadPackString(outputSubmenu[Submenu_listdata], value, sizeof(value));
pred@1953
   568
				ReadPackString(outputSubmenu[Submenu_listdata], text, sizeof(text));
pred@1953
   569
				ReadPackString(outputSubmenu[Submenu_listdata], admin, sizeof(admin));
ds@1952
   570
				
pred@1953
   571
				if (CheckCommandAccess(client, admin, 0))
ds@1952
   572
				{
ds@1952
   573
					AddMenuItem(itemMenu, value, text);
ds@1952
   574
				}
pred@1953
   575
			}
pred@1953
   576
			
pred@1953
   577
			ResetPack(outputSubmenu[Submenu_listdata]);	
ds@1952
   578
		}
ds@1952
   579
		
pred@1953
   580
		SetMenuTitle(itemMenu, outputSubmenu[Submenu_title]);
ds@1952
   581
		
ds@1952
   582
		DisplayMenu(itemMenu, client, MENU_TIME_FOREVER);
ds@1952
   583
	}
ds@1952
   584
	else
ds@1952
   585
	{	
ds@1952
   586
		//nothing else need to be done. Run teh command.
ds@1952
   587
		
ds@1952
   588
		DisplayTopMenu(hAdminMenu, client, TopMenuPosition_LastCategory);
ds@1952
   589
		
pred@1953
   590
		if (outputItem[Item_execute] == Execute_Player) // assume 'player' type execute option
ds@1952
   591
		{
ds@1952
   592
			FakeClientCommand(client, g_command[client]);
ds@1952
   593
		}
ds@1952
   594
		else // assume 'server' type execute option
ds@1952
   595
		{
ds@1952
   596
			InsertServerCommand(g_command[client]);
ds@1952
   597
			ServerExecute();
ds@1952
   598
		}
ds@1952
   599
ds@1952
   600
		g_command[client][0] = '\0';
ds@1952
   601
		g_currentPlace[client][Place_ReplaceNum] = 1;
ds@1952
   602
	}
ds@1952
   603
}
ds@1952
   604
ds@1952
   605
public Menu_Selection(Handle:menu, MenuAction:action, param1, param2)
ds@1952
   606
{
ds@1952
   607
	if (action == MenuAction_End)
ds@1952
   608
	{
ds@1952
   609
		CloseHandle(menu);
ds@1952
   610
	}
ds@1952
   611
	
ds@1952
   612
	if (action == MenuAction_Select)
ds@1952
   613
	{
ds@1952
   614
		new String:info[NAME_LENGTH];
ds@1952
   615
 
ds@1952
   616
		/* Get item info */
ds@1952
   617
		new bool:found = GetMenuItem(menu, param2, info, sizeof(info));
ds@1952
   618
		
ds@1952
   619
		if (!found)
ds@1952
   620
		{
ds@1952
   621
			return;
ds@1952
   622
		}
ds@1952
   623
		
ds@1952
   624
		new String:buffer[6];
ds@1952
   625
		new String:infobuffer[NAME_LENGTH+2];
ds@1952
   626
		Format(infobuffer, sizeof(infobuffer), "\"%s\"", info);
ds@1952
   627
		
ds@1952
   628
		Format(buffer, 5, "#%i", g_currentPlace[param1][Place_ReplaceNum]);
ds@1952
   629
		ReplaceString(g_command[param1], sizeof(g_command[]), buffer, infobuffer);
ds@1952
   630
		//replace #num with the selected option (quoted)
ds@1952
   631
		
ds@1952
   632
		Format(buffer, 5, "@%i", g_currentPlace[param1][Place_ReplaceNum]);
ds@1952
   633
		ReplaceString(g_command[param1], sizeof(g_command[]), buffer, info);
ds@1952
   634
		//replace @num with the selected option (unquoted)
ds@1952
   635
		
ds@1952
   636
		// Increment the parameter counter.
ds@1952
   637
		g_currentPlace[param1][Place_ReplaceNum]++;
ds@1952
   638
		
ds@1952
   639
		ParamCheck(param1);
ds@1952
   640
	}
ds@1952
   641
	
pred@2079
   642
	if (action == MenuAction_Cancel && param2 == MenuCancel_ExitBack)
ds@1952
   643
	{
ds@1952
   644
		//client exited we should go back to submenu i think
ds@1952
   645
		DisplayTopMenu(hAdminMenu, param1, TopMenuPosition_LastCategory);
ds@1952
   646
	}
ds@1952
   647
}