/* 
** Author:       Guardian Bob
** Date:         8/10/01
** Purpsoe:      To give users the power to vote, but not to vote
**               the same maps all the time.
** Requirements: To have the HLDS_LD map voting plugin installed
** Instructions: 1. Compile this plugin
**               2. Put the compiled version in the dlls folder
**               3. Add this plugin to your plugins.ini (be sure to put 
**                  this before the HLDS_LD vote plugin)
*/
 
/* $Id $ */
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
/* Modify this value only */
#define NUM_MAPS 5
 
new used_maps[NUM_MAPS][MAX_NAME_LENGTH];
new ThisMap[MAX_NAME_LENGTH];
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.0";
 
 
public HandleSay(HLCommand,HLData,HLUserName,UserIndex) {
	new Data[MAX_DATA_LENGTH];
	new i;
	new Length;
	new strMap[MAX_DATA_LENGTH];
	new Text[MAX_TEXT_LENGTH];
	new User[MAX_NAME_LENGTH];
	new returnType = PLUGIN_CONTINUE;
 
	convert_string(HLData,Data,MAX_DATA_LENGTH);
	convert_string(HLUserName,User,MAX_DATA_LENGTH);
	strstripquotes(Data);
	Length = strlen(Data);
	if(strmatch(Data,"vote ",strlen("vote "))==1) {
 
		/* we need to strip out 'vote ' (5 characters */
		for(i=5;i<Length+1;i++)
			strMap[i-5] = Data[i];
		strMap[i-5] = NULL_CHAR;
		for(i=0;i<NUM_MAPS;i++){
			if(strcmp(used_maps[i],strMap)==0){
				snprintf(Text, MAX_TEXT_LENGTH, "Sorry, %s, that map cannot be voted at this time.  Please try again at another vote.", User);
				say(Text);
				returnType = PLUGIN_HANDLED;
			}
		}
	}
	return returnType;
}
 
writefile1()
{
	new i = 0;
	new KEY[MAX_TEXT_LENGTH];
	new KEY2[MAX_TEXT_LENGTH];
	new TEXT[MAX_TEXT_LENGTH];
 
	for(i=0;i<NUM_MAPS;i++){
		KEY2="USEDMAP";
		numtostr(i,KEY);
		strcat(KEY2, KEY, MAX_TEXT_LENGTH);
		strcpy( TEXT, used_maps[i], MAX_NAME_LENGTH);
		set_vaultdata(KEY2,TEXT);
	}
 
}
 
readfile1()
{
	new i = 0;
	new KEY[MAX_TEXT_LENGTH];
	new KEY2[MAX_TEXT_LENGTH];
	new TEXT[MAX_TEXT_LENGTH];
 
	for(i=0;i<(NUM_MAPS-1);i++){
		KEY2="USEDMAP";
		numtostr(i, KEY);
		strcat(KEY2, KEY, MAX_TEXT_LENGTH);
		get_vaultdata(KEY2,TEXT,MAX_TEXT_LENGTH);
		strcpy( used_maps[i+1], TEXT, MAX_NAME_LENGTH);
	}
}
 
 
public plugin_init() {
	currentmap(ThisMap, MAX_NAME_LENGTH);
	plugin_registerinfo("Admin hlds_ld-style Map Vote Handler","Stops maps from being voted repeatedly.",STRING_VERSION);
 
	plugin_registercmd("say","HandleSay",ACCESS_ALL);
	exec("echo start");
	readfile1();
	strcpy( used_maps[0], ThisMap, MAX_NAME_LENGTH);
	writefile1();
 
	return PLUGIN_CONTINUE;
}