/* plugin_jack9_chim_silente.sma
   Server Clock Silent Chime Plugin
 
   Coded by Jack9
   "Powered by AdminMod"
 
   Almost entire program ripped from plugin_method_time.sma
   I asked dio if he knew of this plugin, he didnt respond, so I 
   found a suitable template and reworked it (method_time) in about
   2 hours...and made it linux friendly of course so that this could
   be made available to all. I also "cleaned up" as much of method's
   code as I had time.
 
   Notes: 
   All (server)time formats derived from strftime() C/Unix function.
   Check 'man strftime' since SMALL has no reference to it in its manual. 
   Extranneous variables have been left for completeness' sake.
   I have left all my test code (commented out) so that others may use
   it as need be.
 
   jack9@jack9.org
 
   Everyone knows me.
   I am Jack9
   Often wrong but never in doubt.
 
*/
 
#include <core>
#include <console>
#include <string>
#include <admin>
#include <adminlib>
 
new STRING_VERSION[MAX_DATA_LENGTH] = "2.50.0";
new THour[MAX_DATA_LENGTH];
new TMinute[MAX_DATA_LENGTH];
new TValue[MAX_DATA_LENGTH];
new TWDay[MAX_DATA_LENGTH];
new TMonth[MAX_DATA_LENGTH];
new TDay[MAX_DATA_LENGTH];
new TYear[MAX_DATA_LENGTH];
 
new iDelay = 0;
 
public strnsplit(a[],b[],n,m){
	new i;
	for(i=n;i<=m;i++) 
		a[i-n]=b[i];
	return 1;
}
 
public SpeakTime(WithSpeech){
 
	if (systemtime() > iDelay) {
		iDelay = systemtime() + 60;
	} else {
		return PLUGIN_CONTINUE;
	}
 
	new words[5][30];
	new PlaceHolder[MAX_DATA_LENGTH];
	new Text[MAX_DATA_LENGTH];
 
	servertime(THour, MAX_DATA_LENGTH, "%I");
	servertime(TMinute, MAX_DATA_LENGTH, "%M");
	servertime(TValue, MAX_DATA_LENGTH, "%p");
	servertime(TWDay, MAX_DATA_LENGTH, "%A");
	servertime(TMonth, MAX_DATA_LENGTH, "%B");
	servertime(TDay, MAX_DATA_LENGTH, "%d");
	servertime(TYear, MAX_DATA_LENGTH, "%Y");
 
	if(streq(THour, "12")==1) {
		strncpy(words[1], "twelve ", strlen("twelve "),MAX_DATA_LENGTH);
	}
	if(streq(THour, "11")==1) {
		strncpy(words[1], "eleven ", strlen("eleven "),MAX_DATA_LENGTH);
	}
	if(streq(THour, "10")==1) {
		strncpy(words[1], "ten ", strlen("ten "),MAX_DATA_LENGTH);
	}
	if(streq(THour, "09")==1) {
		strncpy(words[1], "nine ", strlen("nine "),MAX_DATA_LENGTH);
	}
	if(streq(THour, "08")==1) {
		strncpy(words[1], "eight ", strlen("eight "),MAX_DATA_LENGTH);
	}
	if(streq(THour, "07")==1) {
		strncpy(words[1], "seven ", strlen("seven "),MAX_DATA_LENGTH);
	}
	if(streq(THour, "06")==1) {
		strncpy(words[1], "six ", strlen("six "),MAX_DATA_LENGTH);
	}
	if(streq(THour, "05")==1) {
		strncpy(words[1], "five ", strlen("five "),MAX_DATA_LENGTH);
	}
	if(streq(THour, "04")==1) {
		strncpy(words[1], "four ", strlen("four "),MAX_DATA_LENGTH);
	}
	if(streq(THour, "03")==1) {
		strncpy(words[1], "three ", strlen("three "),MAX_DATA_LENGTH);
	}
	if(streq(THour, "02")==1) {
		strncpy(words[1], "two ", strlen("two "),MAX_DATA_LENGTH);
	}
	if(streq(THour, "01")==1) {
		strncpy(words[1], "one ", strlen("one "),MAX_DATA_LENGTH);
	}
	strnsplit(PlaceHolder, TMinute, 0, 1);
	if(PlaceHolder[0] == '1') {
		strnsplit(PlaceHolder, TMinute, 1, 2);
		if(PlaceHolder[0] == '0') {
			strncpy(words[2], "ten ", strlen("ten "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '1') {
			strncpy(words[2], "eleven ", strlen("eleven "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '2') {
			strncpy(words[2], "twelve ", strlen("twelve "),MAX_DATA_LENGTH);
		}	
		if(PlaceHolder[0] == '3') {
			strncpy(words[2], "thirteen ", strlen("thirteen "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '4') {
			strncpy(words[2], "fourteen ", strlen("fourteen "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '5') {
			strncpy(words[2], "fifteen ", strlen("fifteen "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '6') {
			strncpy(words[2], "sixteen ", strlen("sixteen "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '7') {
			strncpy(words[2], "seventeen ", strlen("seventeen "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '8') {
			strncpy(words[2], "eighteen ", strlen("eighteen "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '9') {
			strncpy(words[2], "nineteen ", strlen("nineteen "),MAX_DATA_LENGTH);
		}
	}else{	
		strnsplit(PlaceHolder, TMinute, 0, 2);
		if(PlaceHolder[0] == '2') {
			strncpy(words[2], "twenty ", strlen("twenty "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '3') {
			strncpy(words[2], "thirty ", strlen("thirty "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '4') {
			strncpy(words[2], "fourty ", strlen("fourty "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '5') {
			strncpy(words[2], "fifty ", strlen("fifty "),MAX_DATA_LENGTH);
		}else{
			if ( (PlaceHolder[0] == '0') && (PlaceHolder[1] != '0') ) {
		                strncpy(words[2], "boop ", strlen("boop "),MAX_DATA_LENGTH);
		        }                                                                    
		}
		strnsplit(PlaceHolder, TMinute, 1, 2);
		if(PlaceHolder[0] == '1') {
			strncpy(words[3], "one ", strlen("one "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '2') {
			strncpy(words[3], "two ", strlen("two "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '3') {
			strncpy(words[3], "three ", strlen("three "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '4') {
			strncpy(words[3], "four ", strlen("four "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '5') {
			strncpy(words[3], "five ", strlen("five "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '6') {
			strncpy(words[3], "six ", strlen("six "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '7') {
			strncpy(words[3], "seven ", strlen("seven "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '8') {
			strncpy(words[3], "eight ", strlen("eight "),MAX_DATA_LENGTH);
		}
		if(PlaceHolder[0] == '9') {
			strncpy(words[3], "nine ", strlen("nine "),MAX_DATA_LENGTH);
		}
	}
	if(streq(TValue, "AM")==1) {
		strncpy(words[4], "am", strlen("am"),MAX_DATA_LENGTH);
	}
	if(streq(TValue, "PM")==1) {
		strncpy(words[4], "pm", strlen("pm"),MAX_DATA_LENGTH);
	}
 
	if (WithSpeech == 1) {
		snprintf(Text, MAX_TEXT_LENGTH, "[ Current Server Time: %s:%s %s ]", THour, TMinute, TValue);
		say(Text);
		snprintf(Text, MAX_TEXT_LENGTH, "[ %s, %s %s %s ]", TWDay, TMonth, TDay, TYear);
		say(Text);
	}
	return PLUGIN_CONTINUE;
}
 
public chime_check(Timer,Repeat,HLUser,HLParam) {
 
	new Hour_dec[MAX_DATA_LENGTH];
	new Minute_dec[MAX_DATA_LENGTH];
 
	servertime(Hour_dec, MAX_DATA_LENGTH, "%I");	
	servertime(Minute_dec, MAX_DATA_LENGTH, "%M");
 
	if(streq(Minute_dec, "20")==1){
		if(streq(Hour_dec, "04")==1){
			SpeakTime(2);
		}
	}
 
	if(streq(Minute_dec, "30")==1){
		SpeakTime(1);
	}
	if(streq(Minute_dec, "00")==1){
		SpeakTime(1);
	}
	return PLUGIN_CONTINUE;
} 
 
public plugin_init() {
	plugin_registerinfo("Server Chime Plugin", "Speaks server time every hour or so.", STRING_VERSION);
 
	set_timer("chime_check",45,999999);
	return PLUGIN_CONTINUE;
}